_ __ __ _ _ _____ _ _
/ \ | \/ | | ___ __ _| | _____| ___(_)_ __ __| | ___ _ __
/ _ \ | |\/| | | / _ \/ _` | |/ / __| |_ | | '_ \ / _` |/ _ \ '__|
/ ___ \| | | | |__| __/ (_| | <\__ \ _| | | | | | (_| | __/ |
/_/ \_\_| |_|_____\___|\__,_|_|\_\___/_| |_|_| |_|\__,_|\___|_|
介绍
本项目是一款用于自动检测 iOS 项目中【 UIView 和 UIViewController 内存泄漏
】的工具,只需 pod 'AMLeaksFinder'
即可 0 行代码实现自动监控,效果如下,推荐使用 Cocoapods
导入,和 MLeakFinder 的区别可参考 对比 MLeakFinder 。
功能介绍
- 自动监控
Controller
的泄漏; - 自动监控
View
的泄漏; - 借助 FBRetainCycleDetector 快速排查泄漏原因 【
⚠️ 只在ObjC
上有效 】; - 监控到泄漏时支持快速查看泄漏的视图【
View
,Controller View
,View 的 root View
等】; - 更多功能欢迎补充。
Cocoapods
pod 'AMLeaksFinder', '2.1.5', :configurations => ['Debug']
- 如果想查看控制器的强引用链,可导入:Facebook 的 FBRetainCycleDetector 框架即可。
pod 'FBRetainCycleDetector', :git => 'https://github.com/facebook/FBRetainCycleDetector.git', :branch => 'main', :configurations => ['Debug']
直接使用
-
请拖拽
AMLeaksFinder/AMLeaksFinder
文件夹的全部内容到项目 -
启用
和禁用
AMLeaksFinder
请参考AMLeaksFinder.h
的使用说明 (同时release
下为关闭状态)-
打开
MEMORY_LEAKS_FINDER_ENABLED
宏表示启用AMLeaksFinder
-
注释
MEMORY_LEAKS_FINDER_ENABLED
宏表示关闭AMLeaksFinder
-
如果希望
release
也打开请详看AMLeaksFinder.h
文件的宏定义(建议不要打开😄 )
-
原理分析
-
数据结构图
-
项目文件结构
├── AMLeaksFinder
│ ├── AMLeaksFinder.bundle
│ │ ├── all@2x.png
│ │ ├── all@3x.png
│ │ ├── leaks@2x.png
│ │ └── leaks@3x.png
│ ├── Objects
│ │ ├── Controllers
│ │ │ ├── Model
│ │ │ │ ├── AMMemoryLeakDeallocModel.h
│ │ │ │ ├── AMMemoryLeakDeallocModel.m
│ │ │ │ ├── AMMemoryLeakModel.h
│ │ │ │ └── AMMemoryLeakModel.m
│ │ │ ├── NeedDealloc
│ │ │ │ ├── UINavigationController+AMLeaksFinderSwizzleDealloc.m
│ │ │ │ ├── UIPageViewController+AMLeaksFinderSwizzleDealloc.m
│ │ │ │ ├── UISplitViewController+AMLeaksFinderSwizzleDealloc.m
│ │ │ │ ├── UITabBarController+AMLeaksFinderSwizzleDealloc.m
│ │ │ │ ├── UIViewController+AMLeaksFinderSwizzleDealloc.m
│ │ │ │ ├── UIWindow+AMLeaksFinderSwizzleDealloc.m
│ │ │ └── ViewDidLoad
│ │ │ ├── UIViewController+AMLeaksFinderSwizzleViewDidLoad.m
│ │ └── View
│ │ └── Model
│ │ ├── AMViewMemoryLeakDeallocModel.h
│ │ ├── AMViewMemoryLeakDeallocModel.m
│ │ ├── AMViewMemoryLeakModel.h
│ │ └── AMViewMemoryLeakModel.m
│ ├── UI
│ │ ├── AMLeakDataModel.h
│ │ ├── AMLeakDataModel.m
│ │ ├── AMLeakOverviewView.h
│ │ ├── AMLeakOverviewView.m
│ │ ├── AMMemoryLeakView.h
│ │ ├── AMMemoryLeakView.m
│ │ ├── AMMemoryLeakView.xib
│ │ ├── AMSnapedViewViewController.h
│ │ ├── AMSnapedViewViewController.m
│ │ ├── UIViewController+AMLeaksFinderUI.h
│ │ └── UIViewController+AMLeaksFinderUI.m
│ └── Uitis
│ ├── Controller
│ │ ├── UIViewController+AMLeaksFinderTools.h
│ │ └── UIViewController+AMLeaksFinderTools.m
│ └── View
│ ├── UIView+AMLeaksFinderTools.h
│ └── UIView+AMLeaksFinderTools.m
联系
- 欢迎 Issues 和 Pull Requests
- 也可以添加微信 进群吹水。