Best way to close/destroy a webcontainer

So I am dynamically creating a WebContainer object, and using EmbedWithin to add it to a window.
Now I’m done with it, what is the best way to make it disappear and remove the object from memory? (Preventing memory leaks if this is something that happens 100 or so times on a window)

Is this enough?

NewWebContainer.Visible = False NewWebContainer = Nil

I suggest creating a method in the container called closeMe and call this method when you want to close it and make it disappear. closeMe will contain one line of code, as below.

Me.Close

Sometimes you can call MyContainer.Close and it will not close, as the container was created at design time. But using the above will always work in my experience…

I believe it does in most cases.

No. Eric and I demonstrated how you can hide embedded WebContainers, but you cannot remove them using any of:

NewWebContainer.Visible = False NewWebContainer = Nil NewWebContainer.Close 'this one is even mentioned in the Xojo documentation!

The WebContainer still exists on the WebPage. This is true even if you keep an array of WebContainers and work on the array item. The only solution we found to work was Eric’s solution above where you call a Method inside the embedded WebContainer itself e.g.

myWebContainerArray(x).CloseMe

I’m not sure how or why this works, but it does!

There is a definite case where a web container that is not visible wont be removed.

this is a verified feedback report i added <https://xojo.com/issue/35543>

i’m 100% sure that there are other cases where it gets messed up as well though i cant actually track them down.

not that this helps anyone, its just for info :wink:

Just FYI, cases marked Verified do not mean that we agree that it’s a bug. It only means that the tester followed the steps on the case and verified that it behaves the way you described it. It could still be that it’s not a bug.

Thanks Eric and David.
I was having some issues with it, and two things worried me. If there is an EmbedWithin function your linking two objects (Parent/Child), what function breaks the link without loose ends. More importantly, what is the proper way to break the link without memory leaks? I always thought setting an object to a Nil was a destruction event, and the system would handle all the cleanup.

It is either a bug or a ‘by design’. The documentation isn’t clear to me that the embedwithin is a permanent state. Is there a difference between a bug and a feature change in feedback? Their priorities all get voted on by the paid developer community.

The controls in Web are more limited than those in the desktop. In my case, I’m embedding row container objects to get around the issue that the weblistbox isn’t responding to keyboard/mouse events. I’m sure the original design never took my application into account, but I sure worry about how stable my application will be after adding and removing hundreds of webcontainers.

Stable, yes. Speedy? No. We found that loading a couple of hundreds rows of a WebContainer list is very slow. We started to incorporate ‘paging’ to limit our data to 50 or 100 rows at a time. We found that works well.

yeah, i’ve noticed that its not quick. it also seems to slows down if you want to apply a style to the cells based upon the data

@Greg O’Lone So, Am I to take it nobody has looked at it since it was ‘verified’??

[quote=162544:@David Cox]No. Eric and I demonstrated how you can hide embedded WebContainers, but you cannot remove them using any of:

NewWebContainer.Visible = False NewWebContainer = Nil NewWebContainer.Close 'this one is even mentioned in the Xojo documentation!

The WebContainer still exists on the WebPage. This is true even if you keep an array of WebContainers and work on the array item. The only solution we found to work was Eric’s solution above where you call a Method inside the embedded WebContainer itself e.g.

myWebContainerArray(x).CloseMe

I’m not sure how or why this works, but it does![/quote]
Is this still necessary with current versions of Xojo? When I test using Me.Close as noted above, it works fine. But I also see that using the WebContainer’s Close event also kills the WebContainer. At least in my limited testing over here. The way I check for the WebContainer count if, say, MyContainer, in each scenario is to use the following function:

[code]Dim i, counter As Integer
For i = 0 To Self.ControlCount - 1
If Self.ControlAtIndex(i) IsA MyContainer Then
counter = counter + 1
End If
Next

Return counter[/code]