Leaking Images

Hi, I’m leaking a load of Image classes loaded with:

juce::ImageCache::getFromFile( file );

These are the only things leaked and I can’t figure out if I need to do anything to clean them up?

Thx

Hard to imagine. How do you observe the leaks?

The Image is internally reference counted.

Do you allocate the Images on the heap by any chance?
via new Image or in a std::unique_ptr?

They are copyable at zero cost, so you should simply copy-assign them.

hi daniel.

JUCE leak detector is showing them when i close down the app.

Don’t do anything other than call the above function.

Did you click continue? The leaks are usually found cascading.

And do you add a JUCE_LEAK_DETECTOR or JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR in all your classes?

I guess the leaking images are in fact inside an other leaked object.

that’s what’s so strange - there’s nothing above them - just the leaking images.

gonna try it on windows and see what i get

hmmm… alot more stuff showing on Windows for some reason. will get that cleaned up tomorrow.

cleaned the other stuff up. still no idea on the images:

8:55:08.935 *** Leaked objects detected: 17 instance(s) of class CoreGraphicsPixelData

8:55:08.935 JUCE Assertion failure in juce_LeakedObjectDetector.h:92

8:55:11.161 *** Leaked objects detected: 17 instance(s) of class ImagePixelData

8:55:11.162 JUCE Assertion failure in juce_LeakedObjectDetector.h:92

8:55:11.985 *** Leaked objects detected: 19 instance(s) of class Image

8:55:11.985 JUCE Assertion failure in juce_LeakedObjectDetector.h:92

anyone any ideas on this one? thx

@ed95 @t0m
Hi - can someone from JUCE check there isn’t an issue here - I can’t see how to stop these leaks.

thx

Hello,

Just a random guess, in the API there is an explicit function to clear the cache: releaseUnusedImages

Maybe you need to call it in the destructor of your PluginEditor?

1 Like

hi, I’m calling that in the class that does the loading of the images - maybe you’re right, that’s not good enough - I’ll try calling from the editor as you suggest.

no difference. also tried calling that from shutdown() of the Juce::Application and still leaking.
looks like they’re still regarded as being in use for some reason…

Just to rule out another obvious:
You are not using any statics by any chance?
Or Singletons?
When using Singletons remember to inherit from juce::DeletedAtShutdown

juce::SharedResourcePointer should handle the destruction by itself, but maybe have a look there too

2 Likes

ah man, i think I might have stored the containing class in a static at some point - will check that… damn

From JUCE: ImageCache Class Reference

“Another advantage is that after images are released, they will be kept in memory for a few seconds before it is actually deleted”

Is that what’s going on here, could you wait for a few seconds before closing your plugin to see if the leaks still occur?

thanks @daniel - there was a static reference to the containing class which of course would be holding a reference to the images… nice one

1 Like