ios开发 循环引用 检测_iOS之 FBMemoryProfiler FB的循环引用检测工具

经过两天的google终于搞定了FBMemoryProfiler这个开源检测循环引用的工具。中间的曲折也是让人头疼,言归正传直接说一下这个memoryProfiler

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

int main(int argc, char *argv[]) {

[[FBAllocationTrackerManager sharedManager] startTrackingAllocations];

[[FBAllocationTrackerManager sharedManager] enableGenerations];

@autoreleasepool {return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

}

}

然后在appdelegate.m 中添加如下代码

#if DEBUGNSArray*filters = @[FBFilterBlockWithObjectIvarRelation([UIView class], @"_subviewCache"),

FBFilterBlockWithObjectIvarRelation([UIPanGestureRecognizerclass], @"_internalActiveTouches")];

FBObjectGraphConfiguration*configuration =[[FBObjectGraphConfiguration alloc] initWithFilterBlocks:filters

shouldInspectTimers:NO];

memoryProfiler= [[FBMemoryProfiler alloc] initWithPlugins:@[[CacheCleanerPlugin new],

[RetainCycleLoggerPluginnew]]

retainCycleDetectorConfiguration:configuration];

[memoryProfiler enable];#endif

还需要引入头文件

#if DEBUG

#import

#import

#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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值