I’ve tried setting the JUCE_STRICT_REFCOUNTEDPOINTER flag in the Projucer, which is supposed to add more security over the smart-pointers.

My problem is that I use “var” to hold data to pass when drag’n’dropping:

juce::ReferenceCountedObjectPtr<DraggedItem> ptr = new DraggedItem(stuffToStore);       // DraggedItem inherits from ReferenceCountedObject
juce::var sourceDescription(ptr);                       // Error!

container->startDragging(sourceDescription, this);

This code doesn’t work anymore, as var cannot be built via a ReferenceCountedObjectPtr anymore when the flag is set.

So I directly used the ReferenceCountedObject:

auto* obj = new DraggedItem(stuffToStore); // inherits from ReferenceCountedObject
juce::var sourceDescription(obj);

It seems to work, but is it the best practice in that case?