Memory leaks common scenarios and detection using MLeaksFinder
MIT License
Instrument Leaks / Allocations ,Abandoned memory
app
Leaked memory: Memory unreferenced by your application that cannot be used again or freed (also detectable by using the Leaks instrument).
Abandoned memory: Memory still referenced by your application that has no useful purpose.
Cached memory: Memory still referenced by your application that might be used again for better performance.
Leaked memory Abandoned memory Leaks Leaked memory Abandoned memory MRC Leaked memory release ARC Abandoned memoryLeaks
Abandoned memory Instrument Allocations
Mark Generation Allocations App Allocations
push pop UIViewControllerpush pop app push pop dealloc push cache push pop
MLeaksFinder WeRead iOSwereadteamGitHub
MLeaksFinder MLeaksFinder App
debug release
MLeaksFinder
MLeaksFinder NSObject -willDealloc self(2) -assertNotDealloc -assertNotDealloc
2weakSelf nil -assertNotDealloc -assertNotDealloc UIViewController View-ViewController UIViewController presentedViewController view UIView subviews -willDealloc2
MLeaksFinder UIViewController AOP hook UIViewController UINavigationController pop dismiss UIViewController viewDidDisappear:``[self willDealloc]
MLeaksFinder Retain Cycle FBRetainCycleDetector
FBRetainCycleDetectorFacebook OC FBRetainCycleDetector
BlockLeakViewController _block NSMallocBlock _block BlockLeakViewController
pod 'MLeaksFinder'
**1) MLeaksFinder **
UIViewController+MemoryLeak.m + (void)load
app
CocoaPods warnings OTHER_LDFLAGS
warnings warnings Build Settings -> Other Linker Flags -ObjC
FacebookBSD-plus-PatentsFBRetainCycleDetectorpodspecFBRetainCycleDetectorpod 'FBRetainCycleDetector'
PodfileMLeaksFinder.h//#define MEMORY_LEAKS_FINDER_RETAIN_CYCLE_ENABLED 1
**2) MLeaksFinder **
-ObjC
//#define MEMORY_LEAKS_FINDER_RETAIN_CYCLE_ENABLED 1
3) Fail to find a retain cycle
4) MLeaksFinder
//#define MEMORY_LEAKS_FINDER_ENABLED 0
**1. **
AOP hook UIViewController UINavigationController pop dismiss
**2. **
UIViewController view UIView subview UIViewController View-ViewController UIViewController presentedViewController view UIView subviews ViewController UINavigationControllerUISplitViewController viewControllers
**3. **
View-ViewController stack View-ViewController stack stack
**4. **
ViewController cache View ViewController View ViewController pop dismiss -willDealloc
return NO
**5. **
hold popViewController disappear
6. View
View bug
**7. **
MLeaksFinder ViewController View MLeaksFinder UIViewController UIView UIViewController View Model
MLCheck() View-ViewController stack -willDealloc