Dynamic WebDialog Techniques and Memory Leaks

Show and then Close of a WebDialog that is a:

  • Control on a WebPage does not impact the Object Count or Memory Used
  • Property of a WebPage impacts the Object Count and Memory Used
  • Variable in an Event impacts the Object Count and Memory Used

All three examples use AddHandler for the Dismissed Event with RemoveHandler and Sender = Nil in the called Method.

Why do two of the three examples leak memory? The WebDialog instances are not being released. Why aren’t they being released?

Please visit https://dl.dropboxusercontent.com/u/16551982/WebDialogTest.xojo_binary_project to download a test project with the three examples.

Are there problems with techniques two and three? If so, is technique one the only viable way to use WebDialogs or can changes be made to techniques two and/or three so the WebDialog instances are released from memory?

I can reproduce. Is there a feedback case?

[code] dim c as integer = 0

Dim o as Runtime.ObjectIterator=Runtime.IterateObjects
While o.MoveNext
dim n as object = o.Current
if n isa My_WebDialog then
c =c +1
end if
Wend

Self.Runtime_WebLabel.Text = stR©+" Object Count = " + Format(Runtime.ObjectCount, “###,###”) + " Memory Used = " + Format(Runtime.MemoryUsed/1000, “###,###”) + " KB"
[/code]

you can add that to your code and see how dialog objects stay in memory.

1 Like

Dynamic WebDialogs make some of our WebPages SO much faster to load. This is a fugly bug.

<https://xojo.com/issue/33313> Dynamic WebDialog Memory Leak - RemoveHandler and Sender=Nil

[quote=82671:@Christian Schmitz][code] dim c as integer = 0

Dim o as Runtime.ObjectIterator=Runtime.IterateObjects
While o.MoveNext
dim n as object = o.Current
if n isa My_WebDialog then
c =c +1
end if
Wend

Self.Runtime_WebLabel.Text = stR©+" Object Count = " + Format(Runtime.ObjectCount, “###,###”) + " Memory Used = " + Format(Runtime.MemoryUsed/1000, “###,###”) + " KB"
[/code]

you can add that to your code and see how dialog objects stay in memory.[/quote]
Thank you Christian! I’ve updated the test project with your code to reflect the WebDialog Count.

I haven’t looked at the project, but does the memory get released when the session is destroyed? If so, then the memory leak shouldn’t be (too big of) a problem in most applications.

In addition to the WebPage loading faster, there is no waste of extra memory for each WebDialog unless that WebDialog is used. Unfortunately, my experience is that the memory is never released and actually increases with each additional show of the WebDialog. This is a fugly bug!

Have you found a workaround, other than not using dynamic WebDialogs?

Yes. When the Session is destroyed, so are the WebDialog instances. The WebDialog related memory is released too.

For Web Apps that are run all day long by many employees in a business, this bug can mean a significant increase of memory use on the servers. Falling back to non-dynamic WebDialogs can mean much longer load times for the WebPages. It’s a serious bug.

I haven’t had a chance to look at the case yet, but are you setting the dialog property to Nil when you are done with it?

In one of the tests, it’s a local variable in the method, so it’s cleared automatically…

In the Method that is called when the WebDialog is Dismissed, you’ll find RemoveHandler and Sender (aka WebDialog) = Nil. In the example that uses a WebPage Property to reference the WebDialog, I have tried also setting that WebPage Property equal to Nil. The result is the same. Using a WebPage Property or a Variable to reference an instantiated WebDialog leads to a memory leak because the instance is never destroyed/released.

I created this conversation thinking that I might have missed something or used techniques that were known to be bad. It appears that I’m not the only one thinking that each of these techniques should work. If they should, then the underlying bug needs to be fixed. If they should not work then please document another technique for managing dynamic WebDialogs.

Ok. For what it’s worth, the first item:

• Control on a WebPage does not impact the Object Count or Memory Used

Does not affect the object count because it’s an implicit instance. Still looking into why the others leak.

[quote=83375:@Greg O’Lone]Ok. For what it’s worth, the first item:

• Control on a WebPage does not impact the Object Count or Memory Used

Does not affect the object count because it’s an implicit instance.[/quote]
Understood. It was used as a baseline to show that there is a means of using WebDialogs without any memory leaks.

That’s good to hear! Being able to use WebDialogs dynamically is important so I hope you find the problem and fix it well ahead of 2014r2.

At best, it’d be released as part of 2014r2. It’s a framework bug, and you need a new IDE for that.

Bummer. :frowning:

The “At best” part makes it sound like there is a possibility that a fix won’t make it into 2014r2. The only workaround that I’m aware of is to not use dynamic WebDialogs. If that’s an accurate interpretation and the only options are to live with the memory leak or abandon dynamic WebDialogs, please make this fix a priority for 2014r2!

I only meant to say that this fix is not something that we can fix out-of-band from the regular IDE release schedule.

I’m happy to hear that I misunderstood you and even happier that you already fixed it.
<https://xojo.com/issue/33313>
Thanks Greg!

[quote=83638:@Frederick Roller]I’m happy to hear that I misunderstood you and even happier that you already fixed it.
<https://xojo.com/issue/33313>[/quote]
When the beta process starts, please be sure to test this thoroughly and early.