views:

1710

answers:

2

Hi

I am running into this issue of releasing an already released object but can't for the life of me find out where the error is taking place. I have added NSZombieEnabled flag and this is the log I get in gdb. Can someone please tell me how to go about resolving this issue or rather finding out where the error occurred.

*** -[CFString release]: message sent to deallocated instance 0x5e4780 
(gdb) where
#0  0x952ff907 in ___forwarding___ ()
#1  0x952ffa12 in __forwarding_prep_0___ ()
#2  0x9260e20f in NSPopAutoreleasePool ()
#3  0x30a564b0 in _UIApplicationHandleEvent ()
#4  0x31563dea in SendEvent ()
#5  0x3156640c in PurpleEventTimerCallBack ()
#6  0x95280615 in CFRunLoopRunSpecific ()
#7  0x95280cf8 in CFRunLoopRunInMode ()
#8  0x31564600 in GSEventRunModal ()
#9  0x315646c5 in GSEventRun ()
#10 0x30a4ec98 in -[UIApplication _run] ()
#11 0x30a5a094 in UIApplicationMain ()
#12 0x00002494 in main (argc=1, argv=0xbfffef9c) at /Users/adminUser/Projects/MyProject/main.m:14

Thanks.

+14  A: 

The autorelease pool is trying to release an object which already released.

This can happen if you manually release an object registered for autorelease

NSString* foo = [NSString stringWithFormat:@"foo:%d",42];  
[foo release];  /* this release is bad, as this object is already 
registered for autorelease */

You can use the following method, to find the point of allocation:

  1. Set MallocStackLogging, MallocStackLoggingNoCompact environments to 1.
  2. Run the program and once it breaks into gdb use malloc_history from shell to find out the stack trace of the allocation: malloc_history <pid> <addr>. (NSZombieEnabled will print out the address in gdb)
mfazekas
Thanks. Went through the memory management docs again. I was trying to release an object which was being used by another object.
lostInTransit
A: 

yes, i think if we can't create an object using alloc then there is no need of release manually but there is some memory leaks in these string still and i don't know what i need to do.

Please any one can help me..