View Full Version : Trying to find line of code causing error please help!
Jan 11, 2011, 06:56 PM
i'm getting a wonderful -[UIImageView scale]: unrecognized selector sent to instance 0x4b795e0 error I'm trying to find out what instance variable 0x4b795e0 is referring to. Is there a way to find the exact line of code causing this?
Jan 11, 2011, 11:37 PM
That error is a runtime exception. Check the Run > Stop At Objective C exceptions menu item. Run your app til you get the error. You'll see the stack trace and can find your code in it.
It's also possible to use the Allocations Instrument to find what object a particular address refers to.
Make sure to run Build and Analyze on your code first.
This error is usually caused by an under-retain bug.
Jan 12, 2011, 02:15 AM
okay what is an under-retain bug? i released all the retained or allocated objects but i think this is happening because after switching between two views a round rect button i have isn't able to receive already released imageviews. how can i fix all this? i have no idea how to use the consul or the Instruments, I'd just like to find where the line of code is that's causing this or where i need to add code to fix this thanks for the help btw
Jan 12, 2011, 10:58 AM
Have you followed PhoneyDeveloper's advice and turned on the Run > Stop At Objective C Exceptions menu option and/or did a Build and Analyze? If so, what did you learn? If not, why not?
Jan 12, 2011, 11:34 AM
okay what is an under-retain bug? i released all the retained or allocated objects but i think this is happening because after switching between two views a round rect button i have isn't able to receive already released imageviews.
An under-retain bug is similar to an over-release bug. Under-retain is what happens when you fail to retain something you should have. Over-release is what happens when you've called release too many times, or more likely, when you've released something you didn't own.
how can i fix all this? i have no idea how to use the consul or the Instruments, I'd just like to find where the line of code is that's causing this or where i need to add code to fix this thanks for the help btw
You can fix this only by taking a systematic approach to finding the bug. Once you've found it, you can fix it.
Instruments is an important debugging tool for memory management bugs like over-releasing. For example, you can enable zombies as one way to find over-releases. What are zombies?
If you don't know how to use Instruments, now is a good time to learn.
I know of no other effective way of finding bugs than to systematically apply appropriate tools and knowledge. The tools are there. The knowledge is there. It's up to you to acquire and apply them. You're the only person who has the code.
Your only other alternative is to post all your code to some public uploadable website, whenever you have a bug you can't immediately find. Then you would post a complaint at some forum where you can throw yourself on the mercy and goodwill of others. As a debugging strategy, this will quickly become ineffective, at which point you'll have to learn Instruments and the debugger anyway.
Jan 12, 2011, 04:11 PM
sounds like words of wisdom thanks will do