1

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.

4

3 に答える 3

2

ターゲットクラスのカテゴリを使用して、deallocをオーバーライドし、ブレークポイントを設定します。

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

于 2010-06-17T11:00:24.147 に答える
1

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!

于 2010-06-17T10:38:27.827 に答える
1

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?

于 2010-06-17T10:44:06.183 に答える