2
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 )

Antwan van Houdt
  • 6,989
  • 1
  • 29
  • 52

1 Answers1

2

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 to free() or destroy(), even if you call it immediately after alloc 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.

hooleyhoop
  • 9,128
  • 5
  • 37
  • 58
  • No I really tried it 500 times, even given it 5 minutes to "restore" its usage. And yes I do know that ( release not equivalent of free() ) but that doesn't mean it should keep on using the memory – Antwan van Houdt Jul 12 '11 at 15:21
  • I think it has something to do with the file IO, after running "purge" the memory is fine, so the memory is cleared and the system is just too lazy to clean it up ( thus makred as free, free'd when needed ) but that is just a wild guess.. – Antwan van Houdt Jul 12 '11 at 15:26