bug using a webLabel with dictionary

Found a pretty severe bug with a weblabel and a dictionary under a web application. I have attached a sample project. It seems that after 10-15 seconds, the dictionary forgets the object settings of the weblabel being passed to it, but remember other objects (such as listbox, editfield, etc.). Not sure if this is a dictionary bug or a weblabel bug.

To replicate the bug… run the application. Enter something in the textfield to populate it with data. Press the button to populate the label with data. No, refresh the page. The data of the controls SHOULD be saved in the dictionary and referenced and populate the controls on refresh… which is does; however, after 10-15 seconds, the weblabel will not. What’s odd is the dictionary entry on the label is not nil when this happens. So it’s referencing SOMETHING, but whatever it references obviously isn’t being pulled correctly.

Sample project:
https://dl.dropboxusercontent.com/u/13574877/webDictionaryBug.xojo_xml_project

BTW, I’ve tested this on a few controls… and all seems to work as expected. So far, only the webLabel drops its information.

EDIT: Just tested on 2014r1.1… same situation. So, this isn’t new. Also, please excuse my typos. Writing from a netbook PC with a tiny keyboard. :stuck_out_tongue:

Have you filed a bug report in Feedback?

Uh… this is a Global method in a Module. Every WebLabel on every session is going to be written into the same dictionary with a key of “A”, likewise with a WebTextField and a key of “B”.

Just starting up a second session will cause this problem you are seeing.

The fact that you need to initialize the SessionProperties dictionary in App.Open means that it’s not session specific.

And the dictionary has hard references to your controls in yours session which means your sessions won’t get destroyed properly as there are hard references to objects in the session

You probably have caused your own memory issues

Greg, I know this… which is why in my application it’s not based on keys such as “A” or “B”, but with a unique name based on a session identifier (which I have remarked out). The “A” and “B” is for the sake of this example only.

Norman, the dictionary references get removed when my own session handler time out is triggered. That’s not the problem here.

I’m not entirely surprised at this behavior actually. References are top-down, meaning:

Session has a reference to WebPages. WebViews(Pages, Dialogs and Containers) have references to the controls contained within them. Any references going in the other direction are WeakRefs.

One problem you have is that when a WebPage gets closed, it tells each of its child controls to close, which destroys all of the properties of those controls. This is why when you reference those controls later, they “exist”, but have no values associated with them.

Gotcha. I’ll have to come up with another method to save session control information. Is there a ‘standard’ way of doing this? If a visitor refreshes the screen, my intentions are to keep all the information populated that was there before. Listbox content, label content, and textfield content. Instead of storing the object, I guess I just need to store the text and individual cell information of the listboxes. Am I right?

Yup
Save the content not the references to the controls
Quite honestly you’d have the same bug on the desktop for the exact same reason
I took your code and adapted it ever so slightly to a windows that you close and you do get nearly the same problem when the window closes (the control values are destroyed but the control still exists)

Thanks you two… appreciate the feedback. Will adapt what I have to your suggestions and make it work.

Use a cookie instead of a dictionary?

Well, definitely use a Cookie instead of the Session.Identifier. That way, when the user returns, you’ve sure to get the same user each time.

Yes but you can’t cache the control instances - you have to cache the data the controls hold instead

I don’t use the session.identifier… I have my own method that binds a session to a dictionary of current sessions. Session.identifier changes on every refresh/page load. And Norman, I am now. I’m still learning, and appreciate you guys. More trial by error for me, especially lately. Most of my web applications thus far didn’t require session control. Those that did, I made a simple method to control them. Now, I’m wanting something more sophisticated… which stores all the control content so they don’t lose the information they’ve input if they refresh the page. It’ll come right back up to where it was before… even things like the listbox.listIndex and listbox.scrollTo will be stored.

Eric, create a class that holds your SessionData. Make it internalize and externalize JSON data. Use it to populate the controls in your interface. And as users change data in the interface, have the controls adjust the SessionData. That’s the recipe…

Thanks Brad… will definitely look into doing just that.