web app, freeing up memory

I have just started developing a web application. And now I am curious of how to effectively manage memory. The documentation says that Xojo would discard everything once the Window is closed. Very well.

So, my application comes with a startup Webpage. This Webpage may have two items, one textfield and a button.
The button’s action method says: NextPage.show.
On the NextPage, there’s only one Button with action Webpage.show

I tried to illustrate it below:

-------------WebPage 1---------
[BUTTON - action: webpage2.show]

[BUTTON - action: webpage1.show]

Back to the WebPage, the entered text is still in the field. So, there was nothing automatically discarded.

From the documentation I would have expected that because WebPage is closed the memory it consumes would be freed. I looked around but found nothing that lets me free the memory myself.

I am probably missing something but cannot find out what.


Showing another page does not close the previous page…

Yep, this I realize. However, the doc seems to state exactly this.
So, what closes it?

Explicitly call WebPage.Close.

However, if your user is going to frequently flip between the pages just leave them open as this will be faster. It also allows you to easily maintain state as you’ve seen, i.e. your user enters something, changes pages, and when they come back their choice is still there.

Thanks Daniel. That works.

The other question is now how I could examine or set the reference counter. /usr/bin/leaks tells me that I am leaking memory and I would like to fix it… but that’s another thread.

While the online docs suggest that you can set the reference count, the code is not allowed by the compiler. You can get the reference count but it’s not entirely clear to me from the Runtime class documentation how you would get the count for a specific object. It seems like all you can do is get a count of objects in the system, and check the reference count for each one, but which object is at index 5? Or 200? I don’t know how you would map that and figure out the count for a specific object or set of objects (i.e. all instances of a particular class).

Are you sure your app is leaking memory? Xojo apps will gain memory after initial use and then stabilize. If there’s a clear memory leak then there’s a good chance you have a circular reference somewhere and therefore have objects which are not being disposed.

Daniel is correct. If your app leaks then you will get a nice crash fast.