MemoryLeaks

Memory leaks common scenarios and detection using MLeaksFinder

MIT License

Stars
19
Committers
2

Instrument Leaks / Allocations ,Abandoned memory

Leaks

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

Allocations

Abandoned memory Instrument Allocations

Mark Generation Allocations App Allocations

push pop UIViewControllerpush pop app push pop dealloc push cache push pop

  • Allocations

MLeaksFinder

MLeaksFinder WeRead iOSwereadteamGitHub

MLeaksFinder MLeaksFinder App

debug release

MLeaksFinder

  • Instrument

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

Usage

pod 'MLeaksFinder'

FAQ

**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 **

  • MLeaksFinder MLeaksFinder Build Settings -> Other Linker Flags -ObjC
  • MLeaksFinder FBRetainCycleDetector MLeaksFinder.h //#define MEMORY_LEAKS_FINDER_RETAIN_CYCLE_ENABLED 1

3) Fail to find a retain cycle

  • FBRetainCycleDetector

4) MLeaksFinder

  • MLeaksFinder debug MLeaksFinder.h //#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 image.png

MLCheck() View-ViewController stack -willDealloc

https://www.jianshu.com/p/8579be32a538

Related Projects