Skip to content

Instantly share code, notes, and snippets.

@andrewsardone
Last active August 29, 2015 13:58
Show Gist options
  • Save andrewsardone/9993488 to your computer and use it in GitHub Desktop.
Save andrewsardone/9993488 to your computer and use it in GitHub Desktop.
Desired assertion for testing that KVO info isn't leaked when system-under-test is dealloc'd
@interface FooKVOTests : SenTestCase
@end
@implementation FooKVOTests
#pragma mark Observation info leak regression
- (void)test_observation_info_is_not_leaked
{
Foo *__weak foo = [Foo new]; // dealloc foo immediately
expect(foo).to.beNil(); // ✔
// Now assert that foo was not deallocated while key value observers were
// still registered, i.e., I don't want to run the code and see this in the
// log:
//
// An instance 0x109552700 of class Foo was deallocated while key value
// observers were still registered with it. Observation info was leaked,
// and may even become mistakenly attached to some other object. Set a
// breakpoint on NSKVODeallocateBreak to stop here in the debugger.
// Here's the current observation info:
// <NSKeyValueObservationInfo 0x109564770> (
// <NSKeyValueObservance 0x10954a290: Observer: 0x109552700,
// Key path: somePath, Options: <New: NO, Old: NO, Prior: NO>
// Context: 0x10001ddb8, Property: 0x109644ba0>
// )
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment