Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sent to deallocated instance

Whenever I push a view controller onto my stack, then pop it off, I get this error:

*** -[CALayer retainCount]: message sent to deallocated instance <memory address>

It seems to happen right after dealloc is called on the view controller that is being popped off and is exclusive to only this view controller. I'm sure the CALayer has something to do with the view itself, as I do not use them.

Any ideas?

Edit: Here is the backtrace

(gdb) bt
#0  0x01fcd3a7 in ___forwarding___ ()
#1  0x01fa96c2 in __forwarding_prep_0___ ()
#2  0x01fc10e8 in CFGetRetainCount ()
#3  0x01cbc770 in CA::release_root_if_unused ()
#4  0x01cbc707 in x_hash_table_remove_if ()
#5  0x01cbc4ec in CA::Transaction::commit ()
#6  0x01cc4838 in CA::Transaction::observer_callback ()
#7  0x01fa5252 in __CFRunLoopDoObservers ()
#8  0x01fa465f in CFRunLoopRunSpecific ()
#9  0x01fa3c48 in CFRunLoopRunInMode ()
#10 0x027dd615 in GSEventRunModal ()
#11 0x027dd6da in GSEventRun ()
#12 0x0057cfaf in UIApplicationMain ()
#13 0x00002dec in main (argc=1, argv=0xbfffeed0) 
like image 835
skylerl Avatar asked Mar 04 '10 04:03

skylerl


3 Answers

I had similar issue; turns out I was not retaining a UIButton properly. How I found the cause: - Enable zombies - Run the project with 'Allocations' instrument - Use the app to trigger the bug - Check that Instruments show message 'Zombie Messaged' on the timeline - There should be a link that opens CALayer details: when it was allocated and deallocated - You are interested in the place where is was allocated, should be that aha!!! place in your code

Good luck!

like image 90
dimzzy Avatar answered Oct 05 '22 08:10

dimzzy


This is a little bit tricky, mine was a double release in a dealloc function of one of the classes (m/xib) I had in a tableview as a row style. Instruments didn't show much about the object, but checking the callstack was really helpful to pinpoint what class was the one going to -1.

Sample

like image 45
cusquinho Avatar answered Oct 05 '22 08:10

cusquinho


I had a similar issue. My problem was that one of the object variables declared in the interface was mistakenly declared with (nonatomic, assign) and not as (nonatomic, retain), as it should have been. This caused a release message to be sent to an object already with a retain count of 0 (= crash).

like image 32
maralbjo Avatar answered Oct 05 '22 06:10

maralbjo