Coder Social home page Coder Social logo

mlch911 / amleaksfinder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from liangdahong/amleaksfinder

0.0 0.0 0.0 290 KB

A small tool for automatically detecting the [controller, view memory leak] in the project. 一款用于自动检测项目中【控制器内存泄漏,View 内存泄漏】的小工具,支持 ObjC,Swift。

Home Page: https://liangdahong.com/2020/06/08/iOS%E4%B8%AD%E5%A6%82%E4%BD%95%E8%87%AA%E5%8A%A8%E7%9B%91%E6%8E%A7%E6%8E%A7%E5%88%B6%E5%99%A8%E5%86%85%E5%AD%98%E6%B3%84%E6%BC%8F/

License: MIT License

Shell 0.18% Ruby 0.69% Objective-C 97.18% Swift 1.94%

amleaksfinder's Introduction

     _    __  __ _               _        _____ _           _
    / \  |  \/  | |    ___  __ _| | _____|  ___(_)_ __   __| | ___ _ __
   / _ \ | |\/| | |   / _ \/ _` | |/ / __| |_  | | '_ \ / _` |/ _ \ '__|
  / ___ \| |  | | |__|  __/ (_| |   <\__ \  _| | | | | | (_| |  __/ |
 /_/   \_\_|  |_|_____\___|\__,_|_|\_\___/_|   |_|_| |_|\__,_|\___|_|

介绍

本项目是一款用于自动检测 iOS 项目中【 UIView 和 UIViewController 内存泄漏 】的工具,只需 pod 'AMLeaksFinder' 即可 0 行代码实现自动监控,效果如下,推荐使用 Cocoapods 导入,和 MLeakFinder 的区别可参考 对比 MLeakFinder

English 📔

功能介绍

  • 自动监控 Controller 的泄漏;
  • 自动监控 View 的泄漏;
  • 借助 FBRetainCycleDetector 快速排查泄漏原因 【 ⚠️ 只在 ObjC 上有效 】;
  • 监控到泄漏时支持快速查看泄漏的视图【 ViewController ViewView 的 root View 等】;
  • 更多功能欢迎补充。

Cocoapods

pod 'AMLeaksFinder', '2.2.5',  :configurations => ['Debug']

  • 如果想查看控制器的强引用链,可导入:Facebook 的 FBRetainCycleDetector 框架即可。
pod 'FBRetainCycleDetector', :git => 'https://github.com/facebook/FBRetainCycleDetector.git', :branch => 'main', :configurations => ['Debug']
  • 关闭 AMLeaksFinder

    • 在你的代码中定义宏,#define __AUTO_MEMORY_LEAKS_FINDER_ENABLED__ 0 表示关闭
  • 显示/隐藏 AMLeaksFinder 视图

    • 发送通知
      NSNotificationName noti;
      if (显示UI) {
        noti = AMLeaksFinderShowUINotification;
      } else {
        noti = AMLeaksFinderHideUINotification;
      }
      [NSNotificationCenter.defaultCenter postNotificationName:noti object:nil];

直接使用

  • 请拖拽 AMLeaksFinder/AMLeaksFinder 文件夹的全部内容到项目

  • 显示/隐藏 AMLeaksFinder 视图

    • 同上

数据收集

若想收集泄漏相关数据可使用如下 API:

控制器路径变化 AMLeaksFinder.ViewHasLeakVC viewDidDisappear: 2022-04-04 04:21:06 +0000
控制器路径变化 AMHomeVC viewDidAppear: 2022-04-04 04:21:06 +0000
控制器路径变化 AMPresentHasLeakVC viewDidLoad: 2022-04-04 04:21:07 +0000
控制器路径变化 AMPresentHasLeakVC viewDidAppear: 2022-04-04 04:21:07 +0000
控制器路径变化 AMTabBarController viewDidDisappear: 2022-04-04 04:21:07 +0000
控制器路径变化 BMNavigationController viewDidDisappear: 2022-04-04 04:21:07 +0000
控制器路径变化 AMHomeVC viewDidDisappear: 2022-04-04 04:21:07 +0000
控制器路径变化 AMTabBarController viewDidAppear: 2022-04-04 04:21:08 +0000
控制器路径变化 BMNavigationController viewDidAppear: 2022-04-04 04:21:08 +0000
控制器路径变化 AMHomeVC viewDidAppear: 2022-04-04 04:21:08 +0000
控制器路径变化 AMPresentHasLeakVC viewDidDisappear: 2022-04-04 04:21:08 +0000
⚠️👇🏻
视图泄漏: <UIView: 0x7f9849a214d0; frame = (65 176; 294 348); autoresize = RM+BM; layer = <CALayer: 0x60000090ed00>>
视图所在控制器 AMLeaksFinder.ViewHasLeakVC
操作路径:
BMNavigationController(viewDidLoad:) ->
AMTabBarController(viewDidLoad:) ->
AMHomeVC(viewDidLoad:) ->
AMTabBarController(viewDidAppear:) ->
BMNavigationController(viewDidAppear:) ->
AMHomeVC(viewDidAppear:) ->
AMPresentHasLeakVC(viewDidLoad:) ->
AMPresentHasLeakVC(viewDidAppear:) ->
AMTabBarController(viewDidDisappear:) ->
BMNavigationController(viewDidDisappear:) ->
AMHomeVC(viewDidDisappear:) ->
AMTabBarController(viewDidAppear:) ->
BMNavigationController(viewDidAppear:) ->
AMHomeVC(viewDidAppear:) ->
AMPresentHasLeakVC(viewDidDisappear:) ->
AMPresentHasLeakVC(viewDidLoad:) ->
AMPresentHasLeakVC(viewDidAppear:) ->
AMTabBarController(viewDidDisappear:) ->
BMNavigationController(viewDidDisappear:) ->
AMHomeVC(viewDidDisappear:) ->
AMTabBarController(viewDidAppear:) ->
BMNavigationController(viewDidAppear:) ->
AMHomeVC(viewDidAppear:) ->
AMPresentHasLeakVC(viewDidDisappear:) ->
_UIAlertControllerTextFieldViewController(viewDidLoad:) ->
UIAlertController(viewDidLoad:) ->
UIAlertController(viewDidAppear:) ->
UIAlertController(viewDidDisappear:) ->
AMLeaksFinder.ViewHasLeakVC(viewDidLoad:) ->
AMHomeVC(viewDidDisappear:) ->
AMLeaksFinder.ViewHasLeakVC(viewDidAppear:) ->
AMLeaksFinder.ViewHasLeakVC(viewDidDisappear:) ->
AMHomeVC(viewDidAppear:) ->
AMPresentHasLeakVC(viewDidLoad:) ->
AMPresentHasLeakVC(viewDidAppear:) ->
AMTabBarController(viewDidDisappear:) ->
BMNavigationController(viewDidDisappear:) ->
AMHomeVC(viewDidDisappear:) ->
AMTabBarController(viewDidAppear:) ->
BMNavigationController(viewDidAppear:) ->
AMHomeVC(viewDidAppear:) ->
AMPresentHasLeakVC(viewDidDisappear:) ->
⚠️👆🏻

原理分析

├── AMLeaksFinder
   ├── AMLeaksFinder.h
   ├── AMLeaksFinder.m
   ├── 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

联系

amleaksfinder's People

Contributors

liangdahong avatar mlch911 avatar reliable-d avatar jinxiansen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.