Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)testMemory {
- __weak id testingPointer = nil;
- id someObject = // some object with a 'foo' property
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- {
- // Point the weak pointer to the thing we expect to be dealloc'd
- // when we're done.
- id theFoo = [someObject theFoo];
- testingPointer = theFoo;
- [someObject setTheFoo:somethingElse];
- // At this point, we still have a reference to 'theFoo',
- // so 'testingPointer' is still valid. We need to nil it out.
- STAssertNotNil(testingPointer, @"This will never happen, since we're still holding it.")
- theFoo = nil;
- }
- [pool drain];
- // Now the last strong reference to 'theFoo' should be gone, so 'testingPointer' will revert to nil
- STAssertNil(testingPointer, @"Something didn't release %@ when it should have", testingPointer);
- }
Add Comment
Please, Sign In to add comment