juce::Image & shared images

This is probably a dumb question. But I am bit unsure about the constructor of Image which takes a reference.
I.e. this one :

Image ( const Image&) noexcept;

In the function documentation it says:

    /** Creates a shared reference to another image.

        This wont create a duplicate of the image - when Image objects are copied, they simply
        point to the same shared image data. To make sure that an Image object has its own unique,
        unshared internal data, call duplicateIfShared().
    */
    Image (const Image&) noexcept;

So apparently in this case the data is shared between images.

But I wonder: what happens, when the original image is deleted?
Does the new image suddenly point to invalid data, too? Or is there some underlying sharing mechanism, which prevents the actual image data to get deleted, as long as another image is sharing it?

I am asking about this, because I am looking at the new DragAndDropContainer::startDragging method, which takes a ScaledImage. I.e. it works with retina screens! Hooray! Thanks for that btw, JUCE team :slight_smile:
But the ScaledImage is using the “shared” image constructor. And thus I am wondering if I have to be careful with the lifetime of the the image.

Image uses reference counted shared data internally.

Ah, thanks for the fast answer. That’s what I hoped :-).