gyozo kudor
gyozo kudor

Reputation: 6345

How can i see if dealloc is being called on a uikit object, or any object not created by myself

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.

Upvotes: 1

Views: 200

Answers (3)

Mike Weller
Mike Weller

Reputation: 45598

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!

Upvotes: 1

fraca7
fraca7

Reputation: 1188

Use a category on the targeted class to override dealloc and set a breakpoint on it.

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCategories.html

Upvotes: 2

walkytalky
walkytalky

Reputation: 9543

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?

Upvotes: 1

Related Questions