Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The first test will cause a crash with MAZeroingWeakRef. The second test will not.
static void TestKVOReleaseCrash(void)
{
KVOTarget *target = [[KVOTarget alloc] init];
[target addObserver: target forKeyPath: @"key" options: 0 context: NULL];
MAZeroingWeakRef *ref = [[MAZeroingWeakRef alloc] initWithTarget: target];
[target setKey: @"value"];
[target release];
[ref target];
[ref release];
}
static void TestKVOReleaseNoCrash(void)
{
KVOTarget *target = [[KVOTarget alloc] init];
MAZeroingWeakRef *ref = [[MAZeroingWeakRef alloc] initWithTarget: target];
[target addObserver: target forKeyPath: @"key" options: 0 context: NULL];
[target setKey: @"value"];
[target release];
[ref target];
[ref release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.