經過兩天的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