The following program should not leak memory:
int main (int argc, char* argv[])
{
OptionalScopedPointer<Foo> foo;
foo.set (new Foo(), true);
foo.reset();
foo.release();
return 0;
}
A the docs for reset say:
Resets this pointer to null, possibly deleting the object that it holds, if it has ownership of it.
I think reset should be:
void reset()
{
if (! shouldDelete)
object.release();
else
object = nullptr;
}
Code to reproduce: https://github.com/FigBug/juce_bugs/blob/master/OptionalScopedPointer/Source/Main.cpp