Dellee wrote:
Hi all, I am new to myFaces and I think a little bit confusing on the saveState option. When using the saveState, will it keep referencing the beans that it pointed to ? if yes, will this cause a memory leak coz the pointed bean should be died and GC after the server method finished. However, as someone is pointing to it (by saveState), so it still alive and won't be collected when GC start. what do u think ? am i mis-understanding something ?

The t:saveState tag simply "attaches" the object referenced by its value expression to the JSF component tree. That data therefore has exactly the same lifetime as the JSF component tree, and will be discarded when the tree is discarded.

One of the major points of JSF is that when a request completes, the JSF component tree is either stored server-side or encoded in the html page, and then restored to its former state after the user clicks a commandButton or commandLink.

When the same page is being redisplayed repeatedly, the component tree continues to exist [1].

When navigation to a different page occurs, the current JSF component tree is discarded, and a new one created for whatever new page is being displayed. [2]

Using t:saveState ensures that the referenced object is kept around for exactly the same time as the component tree.

[1] In most cases, it's not exactly the same component instances; the data is serialized at the end of the render phase, then in "restore view" an "identical" component tree is recreated with the same contents. This is why the target of a t:saveState tag needs to either implement java.io.Serializable or javax.faces.component.StateHolder.

[2] Well, a configurable number of "old" component trees are cached in memory to support multiple concurrent windows, and back-button usage. This defaults to 20. Component trees only get garbage-collected once they are pushed out of this cache by newer component trees.

Regards,

Simon

Reply via email to