In my mac application I'm currently developing, I have an iKImageBrowserView
which displays something like 500/1000 Images.
Turning off image display, memory consumption is very low around 50 MB.
Turning on image display, memory consumption is very high around 500 MB.
Every time I scroll up/down, memory usage is increased.
Here is a snippet of imageBrowser:itemAtIndex
:
..
MyBrowserNSImageItem *item = [[MyBrowserNSImageItem alloc] initWithCover:coverImage andId:myFile];
return [item autorelease];
where coverImage
is read from an object cache and it is not initialized every time.
How could I decrease memory usage?
Update: I tried to use imageVersion
: from DataSourceProtocol but still high memory usage. If I initializes images but don't pass them to ikImageBrowserView memory is low.
Other Update: I did another test. Every time I allocate an object of a simple PNG image. And this time memory is low. Problem arises only when I use real images. They are JPG of around 50/100KB. Probably when they are loaded in memory they decompress. How can I reduce memory usage of an NSImage?
Update: Problem is in the quality of JPEG. They consume too much memory when displayed. So question is: HOW to generate memory/quality thumbnail in Cocoa?
With the aim of sharing my experience for future readers I found my problem. It was a memory leak in my code. The leak was very trivial in my custom ImageBrowserItem.
As another optimization I switched from NSImage to NSData representation (it consumes less memory).
As a last optimization (that I am going to think) is about quality of thumbnails. I am thinking to show different thumb quality according zoom value. What do you think?