Skip to main content

How do I verify reference count in ARC mode?



I used to verify that same of my variable haves the expected retain count using some [myVar retainCount] under the debugger, especially for var that did not have a custom dealloc.





How do you do this in Arc mode? How do you ensure that there is no memory leak?


Comments

  1. You should never use retainCount for anything, with or without ARC.

    When to use -retainCount?

    ReplyDelete
  2. You don't. ARC handles the memory management for you and does not allow you to call retainCount and even if you could see it, the number it returns is meaningless for you. If you want to you should be doing memory profiling in Instruments with the Leaks and Allocations instruments. That is the best way to look and see how your application is allocating memory and catch any improper use of memory there.

    ReplyDelete
  3. You don't. Apple say you don't need to as ARC will handle it for you.

    ReplyDelete
  4. I believe the only way is to profile your application using the Allocations instrument. You will need to click on the info descriptor (the 'i' next to Allocation in the left pane) and click on "Record Reference Counts". You can then profile your app and do a search for the specific class you're looking to inspect. From there you can find the retain count in the Extended Detail pane for each instance of the class.

    You can also do this using Leaks as well (since I believe it's a variation of the Allocations instrument).

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?