sunprairiedude (1) [Avatar] Offline

I have read the Wicket in Action book cover to cover and is one of the best technical books I have read.

I have a question pertaining to Session Management in Wicket.

The books gives an example of how to create a custom Session object by extending WebSession. Specifically, the CheesrSession Class has a instance variable of Type Cart. I like this approach in that it ensures Type Safety of the data stored within the Session. However, what is not clear to me is how do I purge the instance variables when I no longer need them? If I was using the plain old javax.servlet.HttpSession I could do, session.removeAttribute(attributeName).

Section 1.2 within the books says as follows. ".. One of WicketÂ’s main features is state management. You want this to be transparent so you donÂ’t need to worry about managing state all the time."

Does this imply that Wicket manages the Session like a JVM manages the memory (using GC Threads) so that we don't explicitly have to invoke System.gc()?

Any clarification would be highly appreciated.


Eelco12 (100) [Avatar] Offline
Re: Clearing Session
Hi Murali,

Good to hear you like our book!

To remove an instance variable, just set it to null. You'll still occupy some memory because of the reference, but that shouldn't be a big deal. Or if it is... you can have best of both worlds maybe by exposing a get/ set method for your variable, but just pass that through to getAttribute/ setAttribute in the Session class (protected methods). Then, you could call removeAttribite on Session when setAttribute is called with null, or expose your own delete method.

As for Wicket's state management... Well, what Wicket does well is provide you with a stateful programming model. Your components can have member variables etc without you ever having to wonder how these variables maintain their values between requests. This is quite different from most web frameworks (and in fact when you do web programming without any framework), as you then have to pass request parameters around instead of just working with stateful objects. Look for a few non-trivial Struts or JSP examples to see what I mean.

Finally, memory management... Indeed, you never have to explicitly tell Wicket to release objects, but instead you can rely on Wicket management of your stateful objects in the background. If you want to learn more, look at the source of ISessionStore and its implementations.

Good luck!