Store juce::Image in STL container [SOLVED]

So apparently juce::Images come always as a reference (although the input parameter of my function is a plain juce::Image) and references can’t be stored in STL containers. I managed to store pointers instead, however I get segmentation faults when trying to use the images…
Any Idea what’s wrong here or another way to achieve the same thing?
Thanks, Frederik

Edit: I found a way: you need to call juce::Image::createCopy() before storing, that way you have a new object.

Does this mean you stored juce::Image*?

The juce::Image class itself basically manages a reference-count on the underlying data, so you should be able to do stuff like std::vector<juce::Image> (some JUCE code internally uses juce::Array<juce::Image>, which is similar)

When you do a copy-assignment like someArray.add(myJuceImage) the juce::Image struct is simply copied over, and in that process it increases the reference count on the underlying data (i.e. juce::ImagePixelData). When a juce::Image object is destructed (deleted or goes out of scope) it decreases the count, and if the count is 0 then the underlying data is freed

This way you can just pass around the juce::Image objects, without having to actually make copies of the (much larger!) underlying image data via juce::Image::createCopy()