Given that that argument defaults to false anyway, I don’t see much use in adding explicit support for smart pointers? If you instantiated your component with a std::unique_ptr, why would you pass true to the deleteWhenDismissed argument?
If you used juce::Component::SafePointer, you would get the behaviour you expect as SafePointer will detect when the object is deleted and make itself nullptr accordingly.
Hi Anthony and ImJimmi, thank you for your answers. You are right. I’ve checked again and I can’t understand why I saw that. I will try with juce::Component::SafePointer.
It’s a bit off-topic, but for completeness sake the difference between juce::WeakReference and std::weak_ptr is that the std::weak_ptr can be made thread safe because it can be turned into a std::shared_ptr:
auto safePtr = weakPtr.lock(); // returns a std::shared_ptr that will make sure the object stays alive
safePtr->foo();
With WeakReference:
if (weakReference)
weakReference->foo(); // could get deleted while being used
I know that you are probably aware @anthony-nicholls , just an addition for the readers