0

I am relatively new to Xcode4 and I would like to know how can I identify a double release with it.

In the debugger I see a line like *** -[NSConcreteMutableData release]: message sent to deallocated instance 0x60b63fe0.

The problem is that knowing the address doesn't help a lot identifying the object and also the object type doesn't help too much identifying it.

I read http://www.friday.com/bbum/2010/01/10/using-malloc-to-debug-memory-misuse-in-cocoa/ but I did not found this to be too successful.

EmptyStack
  • 51,274
  • 23
  • 147
  • 178
sorin
  • 161,544
  • 178
  • 535
  • 806

5 Answers5

6

You can enable the NSZombieEnabled environment variable - see How do I set up NSZombieEnabled in Xcode 4? for instructions on how to do this on Xcode 4.

What this means is that released objects are kept around in memory, so the debugger can still find out the type of objects. When the crash occurs, you are told of the object in question.

The "Zombies" Instruments tool is great for detecting bugs of this type - it actually enables NZZombieEnabled and you can use it to find out exactly which line of code the crash occurs.

Community
  • 1
  • 1
m.voong
  • 61
  • 2
1

You can replace the release method using categories for testing purposes, this is not designed to work like that as part of the language but in the past I have found success it trying to do some testing, usually all you find out is that an autorelease pool is releasing you object.

Nathan Day
  • 5,981
  • 2
  • 24
  • 40
  • An act of desperation at best. In this case, the class isn't public API and, thus, acting a category would be hard – bbum Aug 18 '11 at 15:13
  • Well yes, I didn't intend this as something to be part of released code, just a useful technique for trying to identify referencing counting issues. – Nathan Day Aug 18 '11 at 20:45
  • Hence no down point :) -- it'd be very hard to do and, as it is clearly an over-release -- a waste of time compared to using zombies. There certainly are situations that warrant such hackery, though! – bbum Aug 18 '11 at 21:05
0

Use the profiler for Zombies to track down the actual object. It will automatically enable NSZombies and more importantly keep a history of all release and autorelease messages.

  1. Use Profile menu command under Product.
  2. In the profiling template selection dialog that appears, select Zombies.
  3. Click the Record button in the toolbar (Command-R) to begin recording. Use your app normally. If a call is made to a deallocated object, a flag is inserted in the timeline pane and a Zombie Messaged dialog appears.
  4. Click the focus arrow next to the zombie’s memory address to display the memory history of the zombie object in the detail pane, along with corresponding reference counts and method calls.

Here is the apple documentation with pictures:

https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/EradicatingZombies.html

Conor
  • 1,781
  • 17
  • 27
0

You are sending a release message to something which already is released or having retainCount 0. Hence, its giving such an error message. Actually, my answer over here might help.

Community
  • 1
  • 1
mayuur
  • 4,736
  • 4
  • 30
  • 65
-1

Try using the property retainCount. If an object has a retainCount == 0 then it will be freed. Ultimately you will not be able to send it a release message.

Peter Osburg
  • 276
  • 1
  • 4
  • 10