Last active
July 20, 2018 18:43
-
-
Save NSFish/993b5a917470c605c41db4fa6064564d to your computer and use it in GitHub Desktop.
Tagged Pointer to the rescue😂.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Come from https://blog.csdn.net/wangyanchang21/article/details/80570863 | |
@interface SomeClass : NSObject | |
@property (nonatomic, strong) NSString *string; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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