From 42ac10aac3dc7cdffc4cc2ec3a3c46c13599f773 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Tue, 12 Jun 2018 19:32:11 +0100 Subject: [PATCH] Fix crash when call needsMainThreadDeallocation on NSProxy instances #trivial (#965) --- Source/ASMainThreadDeallocation.h | 15 ++++++++++++++- Source/ASMainThreadDeallocation.mm | 9 +++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Source/ASMainThreadDeallocation.h b/Source/ASMainThreadDeallocation.h index 622705f58e..a2aa8249f0 100644 --- a/Source/ASMainThreadDeallocation.h +++ b/Source/ASMainThreadDeallocation.h @@ -34,7 +34,7 @@ NS_ASSUME_NONNULL_BEGIN * class need to be deallocated on the main thread. * You do not access this property yourself. * - * The NSObject implementation returns NO if the class name has + * The NSObject implementation returns YES if the class name has * a prefix UI, AV, or CA. This property is also overridden to * return fixed values for other common classes, such as UIImage, * UIGestureRecognizer, and UIResponder. @@ -43,5 +43,18 @@ NS_ASSUME_NONNULL_BEGIN @end +@interface NSProxy (ASNeedsMainThreadDeallocation) + +/** + * Override this property to indicate that instances of this + * class need to be deallocated on the main thread. + * You do not access this property yourself. + * + * The NSProxy implementation returns NO because + * proxies almost always hold weak references. + */ +@property (class, readonly) BOOL needsMainThreadDeallocation; + +@end NS_ASSUME_NONNULL_END diff --git a/Source/ASMainThreadDeallocation.mm b/Source/ASMainThreadDeallocation.mm index 22763d8200..36c13421cd 100644 --- a/Source/ASMainThreadDeallocation.mm +++ b/Source/ASMainThreadDeallocation.mm @@ -199,3 +199,12 @@ } @end + +@implementation NSProxy (ASNeedsMainThreadDeallocation) + ++ (BOOL)needsMainThreadDeallocation +{ + return NO; +} + +@end