Skip to content

Instantly share code, notes, and snippets.

@marksands
Created February 10, 2015 17:31
Show Gist options
  • Select an option

  • Save marksands/9bc811cc043dea62f105 to your computer and use it in GitHub Desktop.

Select an option

Save marksands/9bc811cc043dea62f105 to your computer and use it in GitHub Desktop.
Testing against strong delegates
#import <UIkit/UIKit.h>
@protocol LOLDelegate
@end
@interface LOLClass : NSObject <LOLDelegate>
@property (nonatomic) id<LOLDelegate> strongDelegate;
@end
#import "LOLClass.h"
@implementation LOLClass
@end
#import <XCTest/XCTest.h>
#import "LOLClass.h"
@interface LOLClassTests : XCTestCase
@end
@implementation LOLClassTests
- (void)testLOLClassHasNoLeaks {
__weak LOLClass *weakObject;
@autoreleasepool {
LOLClass *testObject = [[LOLClass alloc] init];
testObject.strongDelegate = testObject;
weakObject = testObject;
XCTAssertNotNil(weakObject);
testObject = nil;
}
XCTAssertNil(weakObject);
}
@end
@marksands
Copy link
Author

This example will fail on LOLClassTests.m:22, since the retain cycle won't allow testObject to be released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment