您想知道您的 XCTest 是否存在内存泄漏吗?这个工具正是您所需要的。
灵感来自于 Leak Canary 和 HeapInspector。
将以下代码添加到您的测试用例中
- (void)setUp
{
[LeakCanary beginSnapShot:@[@"UIView"]];
}
- (void)tearDown
{
NSSet* leakedObjects = [LeakCanary endSnapShot];
XCTAssertTrue(leakedObjects.count == 0, @"should not have leaked UIView and UIViewController objects");
}
如果您使用 Kiwi
#import <LeakCanary/LeakCanary.h>
#import <Kiwi/Kiwi.h>
beforeEach(^{
[LeakCanary beginSnapShot:@[@"UIView"]];
});
afterEach(^{
NSSet* leakedObjects = [LeakCanary endSnapShot];
[[@(leakedObjects.count) should] equal:@(0)];
});
LeakCanaryiOS 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中:
pod "LeakCanaryiOS"
Hai Feng Kao, [email protected]
LeakCanaryiOS 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。