LifetimeTracker 1.3.3

LifetimeTracker 1.3.3

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2018
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Krzysztof Zabłocki.


Downloads

Total25,565
Week0
Month6,636

Installs

Apps541
Pod Tries2
Test Targets111
powered by Segment

GitHub

Stars1,003
Watchers18
Forks36
Issues1
Contributors5
Pull Requests1

Code

Files4
LOCLines of Code 281


LifetimeTracker

Demo

LifetimeTracker can surface retain cycle / memory issues right as you develop your application, and it will surface them to you immediately, so you can find them with more ease.

Instruments and Memory Graph Debugger are great, but too many times developers forget to check for issues as they close the feature implementation.

If you use those tools sporadicaly many of the issues they surface will require you to investigate the cause, and cost you a lot of time in the process.

Other tools like FBRetainCycleDetector rely on objc runtime magic to find the problems, but that means they can’t really be used for pure Swift classes. This small tool simply focuses on tracking lifetime of objects which means that it can be used in both Objective-C and Swift codebases and it doesn’t rely on any complex or automatic magic behaviour.

Integration

To Integrate visual notifications simply add following line at the start of AppDelegate(didFinishLaunchingWithOptions:):

#if DEBUG
  LifetimeTracker.setup(onUpdate: LifetimeTrackerDashboardIntegration().refreshUI)
#endif

Tracking key actors

Usually you want to use LifetimeTracker to track only key actors in your app, like ViewModels / Controllers etc.

You conform to LifetimeTrackable and call trackLifetime() at the end of your init functions:

class SectionFrontViewController: UIViewController, LifetimeTrackable {
    static var lifetimeConfiguration: LifetimeConfiguration = (identifier: "VC", maxCount: 1)

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        /// ...
        trackLifetime()
    }
}

When you have more than maxCount items alive, the tracker will let you know.

Writing integration tests for memory leaks

You can access the summary label using accessibility identifier LifetimeTracker.summaryLabel, which allows you to write integration tests that end up with looking up whether any issues were found.

License

LifetimeTracker is available under the MIT license. See LICENSE for more information.

Attributions

I’ve used SwiftPlate to generate xcodeproj compatible with CocoaPods and Carthage.