Last active
December 21, 2015 21:49
-
-
Save jberkman/6371425 to your computer and use it in GitHub Desktop.
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
@autoreleasepool { | |
NSCondition *cond = [[NSCondition alloc] init]; | |
[cond lock]; | |
@autoreleasepool { | |
// Use __block and uncomment below for this to work correctly. | |
NSManagedObjectContext * /*__block*/ context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; | |
NSManagedObjectContext * __weak weakContext = context; | |
NSManagedObject * __block obj; | |
[context performBlockAndWait:^{ | |
context.persistentStoreCoordinator = persitentStoreCoordinator(); | |
obj = [NSEntityDescription insertNewObjectForEntityForName:@"Entity" | |
inManagedObjectContext:context]; | |
[context save:nil]; | |
}]; | |
NSLog(@"weakContext is not nil: %@", weakContext); | |
[context performBlock:^{ | |
[cond lock]; | |
//NSLog(@"context is not nil: %@", context); | |
NSLog(@"weakContext is nil: %@", weakContext); | |
NSLog(@"obj.managedObjectContext is not nil? %@", obj.managedObjectContext); | |
[obj.managedObjectContext performBlock:^{ | |
[cond lock]; | |
// Run in Instruments and this shows sending a message to a zombie object. | |
NSLog(@"Objects: %@", obj.managedObjectContext.registeredObjects); | |
// Uncomment this and it works! | |
// context = nil; | |
[cond signal]; | |
}]; | |
[cond unlock]; | |
}]; | |
} | |
[cond wait]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment