Skip to content

Simple utility for runtime tracking number of instances of each class.

License

Notifications You must be signed in to change notification settings

pavelosipov/POSAllocationTracker

Repository files navigation

POSAllocationTracker

Version

POSAllocationTracker is a simple utility for runtime tracking class' instances. Tracker automatically watches for all classes which are using directly or indirectly init method of NSObject during initialization. Tracking is enable in DEBUG builds only, so it doesn't not affect performance of release builds. The idea of the library was born during reading Facebook's article Reducing FOOMs in the Facebook iOS app. Library is extremelly simple to use. There is only one class with a single method in it:

[POSAllocationTracker instanceCountForClass:Dummy.class]

Here is a complete demo from unit tests of the library:

@interface Dummy : NSObject
@end

@implementation Dummy
@end

@interface POSAllocationTrackerTests : XCTestCase

@end

@implementation POSAllocationTrackerTests

- (void)testInstanceCounterCorrectness {
    XCTAssert([POSAllocationTracker instanceCountForClass:Dummy.class] == 0);
    @autoreleasepool {
        __unused Dummy *dummy = [Dummy new];
        XCTAssert([POSAllocationTracker instanceCountForClass:Dummy.class] == 1);
    }
    XCTAssert([POSAllocationTracker instanceCountForClass:Dummy.class] == 0);
}

@end

About

Simple utility for runtime tracking number of instances of each class.

Resources

License

Stars

Watchers

Forks

Packages

No packages published