A memory tool for easy browsing viewControllers in memory over time, using FBMemoryProfiler and FBAllocationTracker and FBRetainCycleDetector.
It also can detect retain cycles of viewControllers.
Here is a small demo
To your podspec add:
pod 'ZJMemoryProfiler'
To start using ZJMemoryProfiler
you'll first need to enable FBAllocationTracker
.
#import <FBAllocationTracker/FBAllocationTrackerManager.h>
int main(int argc, char * argv[]) {
[[FBAllocationTrackerManager sharedManager] startTrackingAllocations];
[[FBAllocationTrackerManager sharedManager] enableGenerations];
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
To enable memory profiler:
#import <ZJMemoryProfiler/ZJMemoryProfiler.h>
ZJMemoryProfiler *memoryProfiler = [ZJMemoryProfiler sharedProfiler];
[memoryProfiler enable];
// Store memory profiler somewhere to extend it's lifetime
_memoryProfiler = memoryProfiler;
Add method to get viewControlls witch you want to browse:
#import <ZJMemoryProfiler/ZJMemoryProfiler.h>
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[ZJMemoryProfiler sharedProfiler] updateViewControllerInfo:self];
}
ZJMemoryProfiler
will show up as a view on the screen. Once tapped, it will recheck the memory usage of current viewController. Double tapped, it will open FBMemoryProfiler in full size mode.
We can also define plugins (check below) and filters for retain cycle detector, that we pass to configuration.
#import <FBRetainCycleDetector/FBStandardGraphEdgeFilters.h>
NSArray *filters = @[FBFilterBlockWithObjectIvarRelation([UIView class], @"_subviewCache")];
FBObjectGraphConfiguration *configuration = [[FBObjectGraphConfiguration alloc] initWithFilterBlocks:filters
shouldInspectTimers:NO];
ZJMemoryProfiler *memoryProfiler = [ZJMemoryProfiler sharedProfiler];
memoryProfiler.enableCheckRetainCycles = YES; // You must enable this fun.
memoryProfiler.fbPlugins = filters;
memoryProfiler.retainCycleDetectorConfiguration = configuration;
[memoryProfiler enable];
We can also add an interval time to check memory automatically.
memoryProfiler.autoCheckIntervalSeconds = 5;
For more details: FBMemoryProfiler