开发者

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 d开发者_开发问答ealloc 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.


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


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?


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜