On GitHub, facebook/FBRetainCycleDetector has picked up 4.2k stars, Objective-C++. iOS library to help detecting retain cycles in runtime.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
An iOS library that finds retain cycles using runtime analysis.
About
Retain cycles are one of the most common ways of creating memory leaks. It's incredibly easy to create a retain cycle, and tends to be hard to spot it.
The goal of FBRetainCycleDetector is to help find retain cycles at runtime.
The features of this project were influenced by Circle.
Installation
Carthage
To your Cartfile add:
github "facebook/FBRetainCycleDetector"
FBRetainCycleDetector is built out from non-debug builds, so when you want to test it, use
carthage update --configuration Debug
CocoaPods
To your podspec add:
pod 'FBRetainCycleDetector'
You'll be able to use FBRetainCycleDetector fully only in Debug builds. This is controlled by compilation flag that can be provided to the build to make it work in other configurations.
- (NSSet<NSArray<FBObjectiveCGraphElement *> *> *)findRetainCycles will return a set of arrays of wrapped objects. It's pretty hard to look at at first, but let's go through it. Every array in this set will represent one retain cycle. Every element in this array is a wrapper around one object in this retain cycle. Check FBObjectiveCGraphElement.
There could also be retain cycles that we would like to omit. It's because not every retain cycle is a leak, and we might want to filter them out.
To do so we need to specify filters:
NSMutableArray *filters = @[
FBFilterBlockWithObjectIvarRelation([UIView class], @"_subviewCache"),
];
// Configuration object can describe filters as well as some options
FBObjectGraphConfiguration *configuration =
[[FBObjectGraphConfiguration alloc] initWithFilterBlocks:filters
shouldInspectTimers:YES];
FBRetainCycleDetector *detector = [[FBRetainCycleDetector alloc] initWithConfiguration:configuration];
[detector addCandidate:myObject];
NSSet *retainCycles = [detector findRetainCycles];
Every filter is a block that having two FBObjectiveCGraphElement objects can say, if their relation is valid.
Check FBStandardGraphEdgeFilters to learn more about how to use filters.
NSTimer
NSTimer can be troublesome as it will retain it's target. Oftentimes it means a retain cycle. FBRetainCycleDetector can detect those,
but if you want to skip them, you can specify that in the configuration you are passing to FBRetainCycleDetector.
Objective-C let's us set associated objects for every object using objc_setAssociatedObject.
These associated objects can lead to retain cycles if we use retaining policies, like OBJC_ASSOCIATION_RETAIN_NONATOMIC. FBRetainCycleDetector can catch these kinds of cycles, but to do so we need to set it up. Early in the application's lifetime, preferably in main.m we can add this:
In the code above [FBAssociationManager hook] will use fishhook to interpose functions objc_setAssociatedObject and objc_resetAssociatedObjects to track associations before they are made.
Getting Candidates
If you want to profile your app, you might want to have an abstraction over how to get candidates for FBRetainCycleDetector. While you can simply track it your own, you can also use FBAllocationTracker. It's a small tool we created that can help you track the objects. It offers simple API that you can query for example for all instances of given class, or all class names currently tracked, etc.
FBAllocationTracker and FBRetainCycleDetector can work nicely together. We have created a small example and drop-in project called FBMemoryProfiler that leverages both these projects. It offers you very basic UI that you can use to track all allocations and force retain cycle detection from UI.
Does facebook/FBRetainCycleDetector have a project website?
No homepage URL was recorded for facebook/FBRetainCycleDetector in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
How many stars does facebook/FBRetainCycleDetector have?
facebook/FBRetainCycleDetector has 4.2k GitHub stars — refresh the page for the live number, or check github.com/facebook/FBRetainCycleDetector. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is facebook/FBRetainCycleDetector open source?
TopGit's metadata for facebook/FBRetainCycleDetector does not record a license. Most public repositories on GitHub ARE open source, but the exact terms vary — verify by opening the LICENSE file directly.
What is facebook/FBRetainCycleDetector?
facebook/FBRetainCycleDetector (facebook/FBRetainCycleDetector) is a Objective-C++ project on GitHub. From the project's own README: iOS library to help detecting retain cycles in runtime.
Where do I read more about facebook/FBRetainCycleDetector?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/facebook/FBRetainCycleDetector is the definitive source.
Read full README in the tab above.
Want a second opinion on FBRetainCycleDetector?
Ask an AI that can read this page — one click and you get its take on FBRetainCycleDetector.