NSImage +内存管理
NSImage *randomImage = [[NSImage alloc] initWithContentsOfURL:imageURL];
[randomImage release];
为什么内存使用率仍然上升?什么在使用该内存?我释放 NSImage 对象。 (不,这不是网址)
NSImage *randomImage = [[NSImage alloc] initWithContentsOfURL:imageURL];
[randomImage release];
Why does the memory usage still go up? What is using that memory? I release the NSImage object. ( no, its not the URL )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
图像可能正在被缓存。看看
[img setCacheMode:]
您是否真的尝试了 500 次或者您猜测其行为?我的猜测是,缓存将在某个上限时被清除 - 也许 50mb 还不够?
需要注意的是,
-release
并不等同于free()
或destroy()
,即使您在之后立即调用它>alloc init
您不应该假设该对象已被清除。这就是为什么-retainCount
滥用者如此讨厌,他们认为这是调试内存管理的好方法。The images are probably being cached. Take a look at
[img setCacheMode:]
Did you actually try doing 500 times or are you guessing at the behaviour? My guess would be that the cache would be cleared at some upper limit - maybe 50mb is not that much?
It is important to note that
-release
is not equivalent tofree()
ordestroy()
, even if you call it immediately afteralloc init
you shouldn't make the assumption that the object has been cleared away. This is why there is so much hate for the-retainCount
abusers that think it is a good way to debug memory management.