What you do here is quite harmless... The page is already in the session (page map and all), so the extra reference to it doesn't hurt. The problem comes when you attach a business object to your page:

/** Dont do this */
class MyPage extends WebPage {
    private MyVeryLargeObject subject;

    // ....
    public MyPage() {
        // get my very large object from database
        subject = MyVeryLargeObjectDao.get();
        // ...
        form.add(new TextField("name", new PropertyModel(MyPage.this, "some.very.large.navigational.structure.name"));
    }
}

The 'subject' instance of the MyVeryLargeObjectDao class will be serialized into the session with each page version. This can get out of hand, because with some business object models, the attached object can become very large. For this we introduced DetachableModels, which will retrieve the data from the database when needed, and will clean up when the data is not needed (at the end of the request for instance).

The other thing to be aware of is not anonymous subclasses of component, but anonymous or nested instances of IModel. Usually you share an instance of a model between two page instances. If you create an anonymous or nested instance of IModel, then you automatically get a 'this' reference to the class that surrounds it. This will usually be the page, but can also be the form or a listview. Anyway, because the reference is /final/, you will copy that reference to the old page, with the model to the new page, thus duplicating the component tree (it gets versioned etc.). This will eventually lead to OutOfMemoryError.

Search in the mailinglist for outofmemoryerror for other descriptions of this behaviour. I doubt that I have done the subject justice.

Martijn

On 12/26/05, karthik Guru <[EMAIL PROTECTED]> wrote:
Yesterday I ran into a wicket blog that does'nt recommend use of anonymous inner classes that refer to the contained page class?
 
I have my component PropertyModels pointing to the contained page properties.
 
In the form onSubmit, i access the Page properties
 
class LoginPage extends WebPage{
 
  LoginPage( ){
   add(new Form("form"){
      onSubmit( ){
        System.out.println(LoginPage.this.name);
      }
 }
 
So if my understand is correct, this programming pattern is not a wicket best practice?
 
thanks
karthik
 



--
Living a wicket life...

Martijn Dashorst - http://www.jroller.com/page/dashorst

Wicket 1.1 is out: http://wicket.sourceforge.net/wicket-1.1

Reply via email to