Correct way to delete a window


#1

Hello, I am having a few issues with freeing windows.

The problem is that when I use DocumentWindow::closeButtonPressed it is a virtual function call.

So if I would delete the window in that callback, I would be basically deleting the this pointer of the virtual function currently running.

Is there something like a dispatcher that can be used for this?


#2

JUCEApplication::quit()? 


#3

Have a look at the docs for that function:

http://www.juce.com/juce/api/classDocumentWindow.html#a71c46283a6fe63f2cad49d01997e16d5

... using 'delete this' is in fact a typical suggested thing to do here!

As long as you know the object isn't going to be directly used afterwards, then calling 'delete this' is safe (even in a virtual function).

If you're actually having a problem, it's probably because you're doing something else too :)


#4

Thanks, I worked around this for now with a timer that handles all windows that need to be deleted.

I will investigate this further later when I have more time.