I have just found out that the forms that are not in current view are unloaded to preserve memory
and then loaded again when they’re accessed.
This breaks the logic of our application (the status of the form elements, for example, is reset to design-time status,
and it was a bit difficult to find out the reason for that).
There can be other implications, of course, especially if we put any logic in onUnload() and onLoad() events.
Can this behavior be fixed somehow in Servoy
so we can control when the forms are unloaded,
or prevent them from unloading,
or be able to return to the status of the form before it was unloaded, etc.
I reckon this is an important issue and would like to know what Servoy developers think about it.
Thank you.
Forms are only loaded when you touch them in code or when you show them in the screen.
Forms unloading happens automatically, which you allready know now.
In the onLoad and onUnload events, there you should set and save the state of your forms.
Any other logic should go in the onShow and onHide event. note that the onShow event gets a first argument of type boolean, indicating whether it’s the first onShow since the form was loaded or not (meaning that it can happen multiple times in a session if the form gets loaded/unloaded multiple times).
In Servoy 4, you can already force the unloading of a form, by removing the form from history (history.removeForm()) and then remove the actual form (solutionModel.removeForm()).
In Servoy 5 you will also be able to force a form to stay loaded, but this has to be used with care. Servoy only starts to unload forms if there are more forms loaded than Servoy has determined that can fit into memory. So, if you prevent too many forms from being unloaded, you risk the change that your entire solution will run out of memory and thus the user will be presented with an exception of some sort.
Bottomline: use the onLoad/onUnload to set and save state and the onShow/onhide to do your businesslogic.
pbakker:
Forms are only loaded when you touch them in code or when you show them in the screen.
Paul, I’m trying to access some forms that are not loaded yet (forms[formName].controller is undefined and forms.formName is ).
What do you mean by touching the form in code? I need to have access to this form and can’t so far.
If you do forms[‘xxx’] or forms.xxx then the form with name “xxx” is touched and automatically loaded if it wasn’t loaded before.
What you say you are experiencing I’ve never seen before. Are you sure the form you are trying to reference exists (meaning: you designed it, or created it using the solutionModel)?
If yes, please file a case with sample solution displaying htis behavior.
If you do forms[‘xxx’] or forms.xxx then the form with name “xxx” is touched and automatically loaded if it wasn’t loaded before.
What you say you are experiencing I’ve never seen before. Are you sure the form you are trying to reference exists (meaning: you designed it, or created it using the solutionModel)?
If yes, please file a case with sample solution displaying htis behavior.
Paul
Ok, Paul, I figured that out.
I was referring to the form using the index of its name:
for(var i = 0; i < forms.allnames.length; i++)
{
forms[i].elements; //trying to access the form by the index
}
It worked for forms that have been loaded.
If I do
forms[forms.allnames*].elements //access the form by its name*
*```*
*then it's fine.*
*Thanks for pointing that out.*
*Cheers,*
*Maria*
“” is a debugger thing. The debugger (like interactive console) will not create forms on the fly for you but it will report that the form isnt used in the client yet at all.
also why are you iterating of all the forms like that?
Its not that then all forms are loaded, because if you dont have enough memory then forms will be unloaded right away in that loop you do.
jcompagner:
also why are you iterating of all the forms like that?
Not doing that any more.
I tried to apply some settings accross the whole application, certain user define field attributes, and wanted to do this at application startup.
However, it turned out that this should be applied in onShow() of each form because now and then forms are unloaded in smart client and the settings are gone.
This sounds like some stuff that should be done in the onluad event, not in the onshow, unless it’s form data related, then the onshow is the right choice, but then do check the first argument of the onShow event, to fire your logic only the first time the form is shown.
pbakker:
This sounds like some stuff that should be done in the onluad event, not in the onshow, unless it’s form data related, then the onshow is the right choice, but then do check the first argument of the onShow event, to fire your logic only the first time the form is shown.
Paul
Yes, it’s data driven, Paul. And it’s only run on the first time the form is shown. Thanks.