(iphone) UIImage memory management problem.

讨论了如何在iOS应用中有效管理UIImage内存,指出 Instruments 工具不考虑UIImage大小,而是通过计算活动UIImage实例的数量来评估内存使用情况。建议通过跟踪UIImage数量来定位内存泄漏,并提供了在频繁创建销毁UIImage时保持应用性能的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:

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.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值