简体   繁体   中英

ARC circular retain detection

I ported some old code over to Objective-C ARC (Automatic Reference Counting) and it seems to work great. Except a rather large, high-level object is not being deallocated when it is popped off of my navigation stack, making me believe I have a retain cycle somewhere that ARC has hidden from me (or at least made difficult to track down). What is the best way to weed out this potential retain cycle and/or what is a good way to determine the cause of a memory leak under ARC? Thanks!

I just transitioned an older app to use ARC. Instruments showed no leaks, but the allocations continued to go up. I found that by looking at the live objects for something that I knew should be deleted, I was able to track down the retains without a release. Here are the basic steps:

  1. Use the Allocations tool in Instruments
  2. Play with your app for a while (if you know what isn't being released, this goes faster)
  3. Change Statistics to Objects in the Allocations jump bar
  4. Sort by Category and find the class name of your unreleased object
  5. Find a living instance and click the little right arrow next to the memory address
  6. Now you can see the history of retains and releases for an object

仪器中对象历史的屏幕截图

The best way is usually to use the Leaks instrument in the Instruments app .

The What's New In Instruments video from WWDC 2011 discusses using Instruments to find retain cycles under ARC, starting about 38 minutes in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM