Bug in WebSession.PageAt(index As Integer).Close

Hi @Greg_O_Lone and @Jason_Parsley,

I am writing you on the forum because you have closed this feedback case (66245) but I think there is really a bug in WebSession.PageAt(index As Integer).Close. If you use that command it does not close the web page.

Let me explain:

I have disabled the “implicit instance” (off) because my project has quite a few web pages and I don’t want them to be loading in memory. When doing this I tried several code snippets to show the new page and close the previous one but without any success:

Snippet_1: (If you use the value 0 it does not work)

While Self.PageCount > 1
  Self.PageAt(1).Close
Wend

Snippet_2: (This should close all pages except the current one but does not work)

For i As Integer = 0 to Self.PageCount-1
  If Self.PageAt(i) <> p then
    Self.PageAt(i).Close
  End If
Next i

These code snippets don’t work and the PageCount doesn’t stop incrementing so I guess that the new pages are not closed. Also when clicking on the button to go to the third page an error occurs. Why?. Any solution?

This is the link to my example: Example_Implicit_Instance_Off

Could you help me and recheck the code, please?. I’m sure you’ll see that it’s not working correctly.

Many thanks in advance.
Sergio

In case you didn’t get my note on the case…

You can’t loop over that array and expect it to work the way you are expecting. Every time you close a page, you must decrement the loop variable because just like an array, elements move downward when something is removed.

After each place where you call Close, you need to have

i = i - 1

How does that explain that the page doesn’t close ?

To my testing it’s clear that in a loop Self (session) .PageCount is NOT updated.

Or Self.PageCount-1 DownTo 0 ?

Thank you for responding @Greg_O_Lone,

but as @DerkJ and I have told you, if you try the example (please) you will see that Self.PageCount is not updated and Self.PageAt(i).Close does not close the corresponding page. Maybe my code is not quite correct but with your suggestion (i = i -1 or Self.PageCount-1 DownTo 0, as @SteveP says) the result is the same.

Check it by yourself.

For i As Integer = Self.PageCount-1 DownTo 0
  If Self.PageAt(i) <> p then
    Self.PageAt(i).Close
  End If
Next i

Sergio

I’m pretty sure there’s a bug in closing web pages. I made a test project very recently that shows PageCount never decreases.

Related thread / post:

Yes it sure looks like a bug

I haven’t done any testing on this but I think the issue here is a different one. On the web version I opened two feedbacks regarding closing and destroying web objects. Basically when closing a web page neither destructors nor close events are invoked. They are only invoked after some time after disconnection when the session is destroyed. In this scenario I imagine that the pages are saved in memory somewhere and that’s why the PageCount is not decremented.

Thanks for the information @Attilio_Punzi . I’m sure you’re right but you’ll be with me that if the window close event is invoked with the command ‘Self.PageAt(i).Close’, it should be closed and free the memory because then (as you rightly say) until the disconnection it would not be released.

Let’s see if @Greg_O_Lone pronounces and clarifies this issue because there is no problem if it is a bug but it should be resolved (if possible in the next release). If it is not a bug, then he should explain to all of us the correct way to close the windows when ‘implicit instance’ is not used (off).

Thanks to all of you who have reviewed this issue, let’s see if we can resolve it :sweat_smile:

Sergio

1 Like

This seems to be a painful issue by now if the pages arn’t actually closed when requested. In Xojo web the memory you have needs to be as low as possible to keep it a decent amout of users/connections happy.

Like to hear from the xojo team about this too!

1 Like

OK, I was able to provide Greg with a simple example that reproduces the PageCount issue. He’s pretty sure he knows what the problem is now. Thanks to everyone for your feedback on this issue.

9 Likes

Just so everyone knows, the thing we’re counting is an array of WeakRefs and they were not getting cleared when the page was closed… but being WeakRefs, at most they’re 8 bytes per opened page. We were not leaking pages.

2 Likes

Thanks for your reply @Geoff_Perlman, I really appreciate it and I’m sure Gregg will solve the problem. I hope it will be for the next release :wink:

Thanks again.
Sergio

Thanks for the explanation @Greg_O_Lone and for “reopening” my Feedback case and “verifying” the bug.

Thanks to all guys. The community of programmers behind Xojo is the best… and it works!!! :relaxed:

Sergio

Thanks for the explanation. As soon as you have time try to fix the mentioned feedback ( 66104 65173 e anche la perdita di memoria dei webcontainer 65196 ) as well because they are really annoying. If you need some more in-depth examples let me know.

If anyone wants to add points is welcome :wink:

Thanks

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.