Wednesday, April 12, 2017 [Tweets] [Favorites]

Automatic Memory Leak Detection on iOS

Facebook:

Automating this process would allow us to find memory leaks faster without much developer involvement. To address that issue, we have built a suite of tools that allow us to automate the process and fix a number of problems in our own codebase. Today, we are excited to announce that we are releasing these tools: FBRetainCycleDetector, FBAllocationTracker, and FBMemoryProfiler.

[…]

Fortunately, Objective-C offers a powerful, introspective, runtime library that can give us enough data to dig into the graph.

[…]

If we know that the reference we are dealing with is a block, we can cast it on a fake structure that imitates a block. After casting the block to a C-struct we know where objects retained by the block are kept. We don’t know, unfortunately, if those references are strong or weak.

To do that we are using a blackbox technique. We create an object that pretends to be a block we want to investigate. Because we know the block’s interface, we know where to look for references this block holds. In place of those references our fake object will have “release detectors.” Release detectors are small objects that are observing release messages sent to them.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment