Page 1 of 1

What is the life of a form variable?

PostPosted: Sun Oct 11, 2015 7:29 pm
by Westy
How long does a form variable remain available in a session?

I assume it is tied to the life of its form. How long does a form persist? Are forms swapped in and out of memory within a session?

Dean

Re: What is the life of a form variable?

PostPosted: Sun Oct 11, 2015 10:54 pm
by mboegem
Hi Dean,

indeed the form variable is bound to the form and therefor has the same lifespan.
whetter a form remains in memory during a session depends on a couple of variables:
- is the form pushed out of the cache to load other forms which are needed
- how often is a particular form used (least used forms are pushed out first)

Best practice is to not depend on variables used on a form, referencing this from a different scope. (no cross-reference of forms / shared state)
When you need to rely on certain variables, put them in a top-level scope (ie. globals, but other top-level scopes are preferred)
And as you can conclude from above: always take care of (re)initialising form variables. (use onLoad/onUnload (when removed from cache), onShow/onHide)

Hope this will clarify the behaviour in order to choose the right approach.

Re: What is the life of a form variable?

PostPosted: Mon Oct 12, 2015 4:34 pm
by Westy
Hi Marc,

Thank you for your reply. What are some examples of top level scopes for variables other than globals?

Dean

Re: What is the life of a form variable?

PostPosted: Mon Oct 12, 2015 7:05 pm
by Bernd.N
Hi Dean,

I guess there are many ways to work with scopes, here is one:
We use a module "base" which holds a form "_base" which is the base root of all other forms in other modules (via several inheritance steps).
In that module "base", we defined about 29 scopes for all main modules respectively themes, e.g. scopes.person, scopes.project or scopes.security .

That way, all scopes are global, and a variable can be accessed everywhere, like scopes.person.currentPersonID (which holds the UUID of the current user).
So our global variables are distributed to several top-level scopes, which makes it easier to keep them apart and to guess the context to which they belong.

In other words, to answer your question, you can define yourself any top-level scopes you need.

Re: What is the life of a form variable?

PostPosted: Mon Oct 12, 2015 9:20 pm
by Westy
Thank you Marc and Bernd.

Dean