So, I’m programming a plugin that loads data from an external file. Some of this data is .png images. After I have the data in memory I load the images using ImageCache::getFromMemory(). It seems that the cache stores the .png data not just the raw pixel data after decompression. This means I can’t release the memory after creating the Image, or things go south.
The question is who’s responsibility is it to later delete the .png data? Does the ImageCache take care of this or do I need to do it manually?
No… Not sure where you got that idea from, the ImageCache stores an Image object, not the source data that was used to create it. If you load some png data then it’s up to you to release that data after you’ve created the Image from it.
Hmmm, strange. Deleting the .png data seems to cause problems. I’ll double check that the deallocation is done correctly, but I had been careful.
If you have problems deleting things then you probably need to be more modern in your approach to memory-management… But if it’s from a file, why not just use ImageFormat::loadFrom (const File&) ?
I’ve checked and the allocation/deallocation is handled correctly. It all happens in one small function, so the flow is easy to follow.
I have a number of different places in the code where the images are loaded. If at any of these the .png data is deallocated after image loading then I’ll run into an issue where images become mixed up . As in the wrong images will be displayed. It’s pretty strange.
I’ll look at the loadFrom function, but my file contains many images as well as other kinds of data and doesn’t seem suitable at first look.