(iphone) UIImage memory management problem.

来源:互联网 发布:淘宝刷到皇冠多少钱 编辑:程序博客网 时间:2024/05/17 09:22

问题:

I'm having trouble with UIImage memory management.
(iphone) my app gets memory warning when instruments shows "all allocations" only 7mb ?

Essentially, I create/destroy UIImage many times.
Even if I make memory consumption at a time low using local NSAutoreleasePool, iphone/ipad device keeps complaining about memory usage.

I'm thinking, I should allocate UIImage to specific memory buffer(or pool of buffer) which I can designate to.
Is this possible?

Or any other suggestion on how to create/destroy UIImages many times without upsetting iOS would be much appreciated.

Thank you.



回答:

It is not a well known fact, but Instruments does not consider the size of UIImages within the allocated memory. You could be leaking 100Mb of UIImages and the allocated memory would not tell the story. What does tell the story is the number of live UIImage instances at a given moment.

In the Allocations instrument, using the top-right search box, search for "Image". Then look for the column labeled #linving in UIImage. That number is the number of UIImage objects. That is a better compass in to figuring out where are your UIImages going. If at some point you have more objects than what you expect, and thease UImages are not going away you have a UIImage leak in your hands. An UIImage leak will kill your app real fast.



原创粉丝点击