The best solution is simply
- (void)testDealloc { __weak CLASS *weakReference; @autoreleasepool { CLASS *reference = [[CLASS alloc] init];
This creates an instance of the class that we want to free inside @autorealase , which will be released (if we don't get lost) as soon as we exit the block. weakReference will contain a reference to the instance without saving it, which will be set to nil .
source share