Giter Club home page Giter Club logo

leakdetect's Introduction

Leak Detect


A Tool to Detect Swift Potential Leaks

Installation

brew install mint
mint install yume190/LeakDetect

Usage

leakDetect \
    --module "SCHEME NAME" \
    --file Sample.xcworkspace

leakDetect \
    --module "SCHEME NAME" \
    --file Sample.xcodeproj

# spm
leakDetect \
    --module TARGET_NAME \
    --file .

# file
leakDetect \
    --sdk macosx \
    --file xxx.swift

Usage(Github Action)

jobs:
  build:

    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v3
    - uses: yume190/[email protected]
      with:
        # https://github.com/antranapp/LeakDetector
        module: LeakDetectorDemo
        file: LeakDetectorDemo.xcworkspace
        token: ${{secrets.GITHUB_TOKEN}}

Skip List

default path is .leakdetect.yml, or you can use --skip list.yml.

functions:
  # objc function `Dispatch.DispatchQueue.main.async {...}`
  - module: Dispatch
    types:
    - name: DispatchQueue
      instance_functions:
      - async
      - asyncAfter
  # static function `UIKit.UIView.UIView.anmiate {...}`
  - module: UIKit.UIView
    types:
    - name: UIView
      static_functions:
      - animate
  # Some Special case
  - module: YOUR_MODULE_NAME
    types:
    # global function `func escape(...) {}`
    - name: ""
      instance_functions:
      - escape
    # constructor `struct A {...}`
    # A(...) {}
    - name: A
      static_functions:
      - init
    # Nested Type A.B
    - name: A.B
    # Generic Type C<T>.D<U>
    # ignore generic
    - name: C.D

Mode

Detect assign instance function.

  1. x = self.func

    • Check function is instance function.
    • Check self is struct
  2. y(self.func)

    • Check function is instance function.
    • Check parameter is escaping closure

see Don't use this syntax!.

func escape(block: @escaping () -> Void) {}
class Temp {
  func instanceFunction() {}
  func leak() {
    let x = self.instanceFunction
    escape(block: self.instanceFunction)
  }
}

Capture

Detect instance captured by blocks(closure/function).

Example

# Example:
git clone https://github.com/antranapp/LeakDetector
cd LeakDetector

leakDetect \
    --module LeakDetectorDemo \
    --file LeakDetectorDemo.xcworkspace

leakdetect's People

Contributors

yume190 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

leakdetect's Issues

Build Setting not found, quit.

截圖 2023-04-30 下午2 21 35

% export PROJECT_TEMP_ROOT=/Users/ayi/Library/Developer/Xcode/DerivedData/LeakDetectorDemo-dosmmgmlthweliewidnccljtldkn/
% export PROJECT_PATH=LeakDetectorDemo.xcworkspace
% export TARGET_NAME=LeakDetectorDemo
% leakDetect --mode capture
Build Setting not found, quit.

Why can't capture?

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.