Skip to content

Instantly share code, notes, and snippets.

@NSFish
Last active July 20, 2018 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NSFish/993b5a917470c605c41db4fa6064564d to your computer and use it in GitHub Desktop.
Save NSFish/993b5a917470c605c41db4fa6064564d to your computer and use it in GitHub Desktop.
Tagged Pointer to the rescue😂.
// Come from https://blog.csdn.net/wangyanchang21/article/details/80570863
@interface SomeClass : NSObject
@property (nonatomic, strong) NSString *string;
@end
@implementation SomeClass
- (void)someMethod
{
dispatch_queue_t queue = dispatch_queue_create("memoryBeingFreedCase_4", DISPATCH_QUEUE_CONCURRENT);
for (int i = 0; i < 1000000; i++)
{
dispatch_async(queue, ^{
// Will crash at some point due to release in the setter.
self.string = [NSString stringWithFormat:@"The num is %d", i];
// Tagged Pointer will be fine since its just a pointer on stack
self.string = [NSString stringWithFormat:@"%d", i];
});
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment