I think i have an UIImage that has a higher retain count than it should have and i am probably leaking memory. I use this image as a thumbnail, to set a custom background to a uibutton. So the uibutton is holding a reference to it and so do i. But instead of 2, the retainCount is 3. Do i have to create a custom UIImage derived class and override dealloc if I want to place a log message there and then change the class used from UIImage to my class, or is there an easier way. Thanks in advance.
views:
41answers:
3How can i see if dealloc is being called on a uikit object, or any object not created by myself
I would suggest you use the "Leaks" tool in Instruments. It will tell you if you have a leak or not and give you all the information you need.
Update:
I've just been watching a WWDC 2010 video "Future Proofing your Application" where the Apple engineer states that on OS 2.x [UIImage imageNamed:]
actually leaks with a retain count 1 more than it should be. So if your device is running iPhone OS 2.x then that would be why!
Do you know the object is leaking? It's pretty much always a bad idea to leap to conclusions based on retain counts. Use Build & Analyze, Leaks and so on to determine if you've a problem.
If you really want to subclass and log dealloc
, you can, but what is it actually going to tell you?
Use a category on the targeted class to override dealloc and set a breakpoint on it.