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?
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
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
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
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.
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.
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.
Thanks for the explanation. As soon as you have time try to fix the mentioned feedback ( 6610465173 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.