Question

I'm working on an iPad app in which I have a table view. When the user selects a row in the table, I use didSelectRowAtIndexPath to open a popover. I'm getting an error message saying "message sent to deallocated instance" when I try to use a certain button. I originally though the errors was getting thrown by the popover (in it's viewDidLoad or something), so I put a breakpoint in and stepped through the code. To my surprise, I was able to step all the way through the loading of the popover and the rest of the didSelectRowAtIndexPath on my table view (which actually just involves stepping out of some if blocks). The error then gets thrown when I get a couple steps into the automatically generated code that doesn't appear in any of my class files (that looks like 0x0010d71d <+1164> mov 0x6...).

So, my question is, how do I find where this error is being thrown? Is there another method that is automatically run after didSelectRowAtIndexPath that could be getting messed up somewhere?

Was it helpful?

Solution 2

Okay, everyone's responses lead me to find malloc error -[CFString release], which helped me figure out I had a string in my popover that I alloc in viewDidLoad by

myString = [NSMutableString stringWithString:[myGlobalFunctionClass getMyString]];

Since I alloc it this way, it gets set to autorelease. The problem was I was explicitly [myString release]; and myString = nil; in viewWillAppear. Removing the release and =nil parts cleaned up my error.

To answer the actual question that I posted, I believe the autorelease wasn't firing until the simulator actually tried to display the popover (which would run after didSelectRowAtIndexPath). Since that occurs after I explicitly [myString release] in viewWillAppear, it was trying to autorelease something that was no longer there. Just to reiterate, the proper way to do it was let it autorelease at the end, and not [myString release] anywhere in my code.

Can someone verify that this is correct? As I mentioned in my comments, I'm still very new to iOS development. I have a feeling at the end of this project, I'm going to be able to go back to first stuff I did in it and make dozens of improvements in terms of doing things more efficiently and more in accordance with best practice.

OTHER TIPS

Enable NSZombieEnabled in your DEBUG build (see How do I set up NSZombieEnabled in Xcode 4?) to locate instances of objects you're accessing that have been deallocated/released.

Also, consider upgrading your project to ARC, which will likely resolve memory management issues like this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top