Implicit Window instance

Trying to wrap my head around what is happening here and where the fault is in my thinking?

I am trying to switch to explicit instances off windows and in order to do this I created a small project to investigate how to do this.

In the open event of the app I create a variable to hold a reference to the window and a save another reference to a app.property
Now I expected that the variable would go out of scope at the end of the open event,
but when I examine the runtime enviroment wherever I break into the debugger I always have 2 windows.

So what am I missing here or where is my faulty assumption ( i can seem to find it)

Example Project

Thanks in advance for the help.

Project cannot be downloaded. Clicking on the link “Direct download” does not do anything.

No I wouldnt.

I would expect that

But the window wont die until it is closed or set to nil.
Not sure what you are testing here… (why create a window but not show it?)

I would add properties to the App or a global module, and use those, not create a variable in the app.open event.
You can use the public variables to refer to your windows at any time.
You can close and nil the windows at any time.
An Xojo tidies up the lot when you close the app

Hi Jeff,

Thank you for the reply.

I am testing the general principle of creating and destroying a window object.

When the var that contains the window reference I would expect that the window also would get destroyed.
As fas as I understand that happens with every object reference in a variable that goes out of scope.

Are you saying that vars containing a window reference are the exception?

A Window needs to (or rather should) be closed by the Close() command anyway.

Hallo Eli,

Thank you for trying, the link is a link to a file in a directory.

So click the title beneath the document icon, it will take you to the document page where you should be able to download the file.
(Just to be sure I just did another test to verify that it worked)

That link on this document page does not do anything.

Did you use the dropdown menu to select download?

Yes. Nothing happens when clicking on “Direct download”.

That is really strange, I just tested it on 2 different mac and 2 browser and it all works here.

Here is a direct link to the file (instead of the directory)
Example project file

Nope, the link does not do anything. I’m on macOS Sierra / Safari.

I tested it on macOS 10.12.6 and 10.11.6 in Safari and Firefox and both off them work. (really strange)

I tought I could also use iCloud to send a link, but that doesn’t seem to be the case.
Don’t know how I can get you the file then, if I come up with another way I will let you know.

When did you have a look at the variables in the debugger?

I added a show in App.open

owMain.Title = "Property Window" owMain.Show

Then I added a button to the window. Gave it an Action event. The code in there is a simple “beep”, which allows me to view the debugger. There is only one window for the app - owMain.

// dim owMainSecond as new wMain // owMainSecond.Title = "Second Window" // owMain = new wMain // owMain.Title = "Property Window" // beep // // When leaving this event method you would expect that owMainSecond does not longer exist.
Last line is within your method’s scope of course. So owMainSecond is not out of scope at that moment. Set a BREAK statement into App.CancelClose and check RuntimeObjects. You will see that only one window exists in memory.

I let the app run trough it’s entire startup routine and when it’s waiting for a user action I click the pause button of the debugger.
Then when I examine the globals there are Windows (2).

( I also need to find out how to display an image on the forum this doesn’t seem to work. Not in preview anyway)

If you use the first link into the dropbox directory you can see the image.

Example Project

I also placed a break statement in a Menu event under File:New

Disregard my comment above.

Apparently you need to call Close() or a window will stay in memory – even if you set all the references to the window to Nil. Since I always call Close() I was not aware of that.

I assume this is also the reason for the Window() and WindowCount() methods, as one can have windows without any references to them.

Hallo Beatrix,
Thank you for helping out with this.

[quote=347629:@Beatrix Willius]When did you have a look at the variables in the debugger?

I added a show in App.open

owMain.Title = "Property Window" owMain.Show

Then I added a button to the window. Gave it an Action event. The code in there is a simple “beep”, which allows me to view the debugger. There is only one window for the app - owMain.[/quote]

I tried this too and I am getting the same result as previously.
I am using Xojo 2017r2, let me try with some other versions of Xojo.

Hi Eli,

Tried that, placed a owMainSecond.close as the last line in App.Open and indeed that is the solution.

So a Window will only gets destroyed when the close event is called on that window.
So the expectation that when the variable holding a Window reference goes out of scope the window is destroyed
was my false assumption i was working under.

Thank you all for helping me clarify this issue.

p.s. I will leave the stuff in the dropbox for another couple of day’s but then I will remove them.

Yes, but I see you have had that confirmed while I was away.