Is this a memory leak?

I am noticing that the memory increases by about 20MB each time a form is opened within my project. I have the following

dim frm as new frmDisplay
frm = nil

I have this as the action on a button and I am concerned that if the project is running for a long time it is going to each loads of memory. Am I doing something wrong, should I be doing something else to force the window to release the memory its using?

Should you not do

frm.close frm = nil

I may be mistaken, but close does some house cleaning, such as destroying controls and letting the system clear objects, which simply nilling the property may not do.

I am doing the close in the window to close the modal window is that not right?

Is frmDisplay blank? Or could there be an object on it that’s causing the leak?

@Kem Tekinay - the frmDisplay has lots of things on it but I thought that when a window is closed and made nil that everything on it gets garbage collected, is that not correct?

So, that is a desktop project, right ?

Xojo does not do garbage collection. It does reference counting.

If you keep a reference to an object, it may stay around, although the window has been closed. Same thing for addhandler.

You may want to built a smaller project around your leaking form and file a report. 20Mb is not small.

@Michel Bujardet I have just done a small test with a desktop (on Mac) project which has a window with a button on that opens another window which has a button on that closes the window. Each time I press the first button it opens the modal window and the memory usage is about 2MB but when the window closes and set to nil the memory is not released. Each time I repeat the cycle an each time the memory increases by 2MB and thats with a single button on it.

This may not answer your question, but I use a different approach: show/hide, not open/close. When I need to show the user a window, I will call .show on the instance of the window. When the user is done with that window, I call .hide on it, and then do any reset logic I need (clear out fields, reset selections, etc) so that it is ready for the next time the user needs to see it.

That way I’m not allocating a bunch of memory for complex UI in windows that are opened/closed all the time.

@Kimball Larsen I had thought about doing that but I have about 30 windows and each of them have panels with about 10 pages and each panel has many UI objects and the idea of having to reset, tidy up these was part of the reason I decided it would be easier to close the window and reopen it fresh each time. That said I can see the benefit of your way of doing it. It just seams odd that when the window is closed the memory is not released.

You may just have found the issue we discuss in the other thread:

To summarize:

Closing a window does not free the undelaying is object and the memory used for the window stays used.
With a retina iMac this can be 40 MB for a full screen window.

@Christian Schmidt I think you are probably right as all the windows I am opening are full screen and on a 27" iMac that is a big amount of memory. Thanks, I thought it was something I was doing wrong but looks like I stumbled on a bug without realising.