Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone development - memory release issue

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.

like image 452
lostInTransit Avatar asked Jan 27 '09 05:01

lostInTransit


People also ask

Why does Xcode use so much memory?

For each OS, it has simulator runtimes, libraries, compilers, and software development kits. It has a ton of data about declarations supported in each operating system. That's why it's so huge.

What is memory leak in iOS?

As per Apple, a memory leak is:Memory that was allocated at some point, but was never released and is no longer referenced by your app. Since there are no references to it, there's now no way to release it and the memory can't be used again.

How much RAM do I need for iOS development?

How much RAM do I need? Short answer: At least 8GB, better 16 GB. Long answer: 8GB is a good start and you should be able to run a single Simulator plus Safari with many tabs easily on it without many hiccups.

How much memory is too much for iOS app?

16GB of RAM is the highest amount of RAM ever offered in an iPhone or iPad, and the 5GB limitation means that apps aren't able to utilize even half of what the iPad Pro has to offer.


1 Answers

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)

Another option (that is less likely to slow down your runtime performance) is to use the Instruments tool with the "Zombies" template. It will track zombies and also tell you the history of a zombie without having to use the malloc_history command.

like image 154
mfazekas Avatar answered Oct 16 '22 14:10

mfazekas