When does a window goes nil?

When a modal window is created and shown via code, does the objct for this window gets nil when the window is closed, or do I have to store the objects variable and then set it to nil to prevent memory leaks?

Objects in Xojo are reference counted. As long as at least one variable points to an object the reference count is more than 0, so the object lives. If the reference count drops to 0 the object is immediately removed from memory.

Calling Close() on a window is a completely different thing. The object still exists afterwards, but most probably in a inconsistent state For example controls will be Nil (unless something points to them from outside of the window which would keep the controls reference count above 0).

Memory leaks can happen of course. During debugging I check that the Destructor is called on every of my objects. If one is not called at the expected time, I know I have a reference count of more than 0 at that specific moment.

It should stay viable while you are still inside the method that created it.
This allows you to query properties and methods of a closed modal window for a while


[code]Sub MySub()

dim x as new MyModal
dim y as integer


y = x.PublicIntegerProperty

//more code here

//more code here

end sub // x should go nil once the sub is finished, and the window goes out of scope.[/code]

Thanks for the answers.

The window goes out of scope when the sub finished. The modal window is still visible and in memory and no variable has a reference to it. When the dialog is now closed with the Red blose button does the window goes nil or does it stay in memory?

Very good idea with checking the destructor. The window goes nil when the window is closed!

Then it isn’t being shown modally.
Execution stops while the window is displayed: the sub should not complete until the window is at least hidden…

You are right Jeff,

it is not a modal dialog. Sorry, I changed the behaviour of my apps about dialog from modal to normal window short time before I started this conversation. So I meant the right thing but wrote the wrong thing :wink: