经过两天的google终于搞定了FBMemoryProfiler这个开源检测循环引用的工具。中间的曲折也是让人头疼,言归正传直接说一下这个memoryProfiler
github:https://github.com/chengxiaoyu00/FBMemoryProfiler
1· 先介绍下这个开源工具:
An iOS library providing developer tools for browsing objects in memory over time, using FBAllocationTracker andFBRetainCycleDetector.
基于FBAllocationTracker and FBRetainCycleDetector 开发的一个检测iOS app内存的工具
2· 如何将工具集成到自己的工程:
现在github提供两种方法供开发者使用 :(Carthage 和CocoaPods)
这里我就拿pod说一下,Carthage可以自行google 因为用pod的人比较多集成起来也比较方便
只需要在你工程的podfile中添加:
pod 'FBMemoryProfiler'
然后执行
pod install --verbose --no-repo-update
pod install 估计是不能用啦,因为great wall
3·没什么问题那就到了使用阶段:
使用起来也是很方便的首先在main.m中添加如下代码
#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])); } }
然后在appdelegate.m 中添加如下代码
#if DEBUG NSArray *filters = @[FBFilterBlockWithObjectIvarRelation([UIView class], @"_subviewCache"), FBFilterBlockWithObjectIvarRelation([UIPanGestureRecognizer class], @"_internalActiveTouches")]; FBObjectGraphConfiguration *configuration = [[FBObjectGraphConfiguration alloc] initWithFilterBlocks:filters shouldInspectTimers:NO]; memoryProfiler = [[FBMemoryProfiler alloc] initWithPlugins:@[[CacheCleanerPlugin new], [RetainCycleLoggerPlugin new]] retainCycleDetectorConfiguration:configuration]; [memoryProfiler enable]; #endif
还需要引入头文件
#if DEBUG #import <FBMemoryProfiler/FBMemoryProfiler.h> #import <FBRetainCycleDetector/FBRetainCycleDetector.h> #import "CacheCleanerPlugin.h" #import "RetainCycleLoggerPlugin.h" #endif
CacheCleanerPlugin.h和
RetainCycleLoggerPlugin.h
我会在下面附带下载地址
好了到目前为止已经可以使用这个工具了具体工具的功能很多大家可以自行开发理解,fb的东西还是良心之作的
这里强调下我的pod版本是最新的,而且你的podfile文件最好按照现在的标准去创建不然可能会提示你pod search 不到FBMenoryProfiler 、
还有这个工具支持版本不能低于8.0 ,到时候启动不了提示你 :dyld: Library not loaded: @rpath/FBAllocationTracker.framework/FBAllocationTracker
Referenced from: /
别怕google一下,具体答案自己去找一下很好改!
下面来一个jif