You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Esteban Ignacio Masoero <em...@getsense.com.ar> on 2009/09/24 05:09:33 UTC

Old instances of a page remain in memory (apparently) forever

Hi:
I'm not sure whether this behavior is normal or not, so I'm going to
describe it and I hope someone can tell me if I'm doing something wrong or
if there's just nothing wrong!

In my app I found out that each time a request is made, old instances of a
page remain in memory, and get accumulated in time (I noticed this behavior
by looking at the "All instances" feature from eclipse debug's perspective).
I searched the code for bad practices like anonyomus Model classes, but I
didn't find those kind of thins. So finally I created a new simple project
to test whether this behaviour repeated there too, and I found out that it
did!

Here's the new simple project code (wicket 1.3.5, tomcat 6, eclipse
galileo):

public class MyApp extends WebApplication {
@Override
 public Class getHomePage() {
return MyPage.class;
}
}

public class MyPage extends WebPage {
private String text;
public MyPage() {
 this("<notext>");
}
public MyPage(String textt) {
 super();
this.text = textt;
Form form = new Form("form"){
 private static final long serialVersionUID = -3566834353426372805L;
@Override
 protected void onSubmit() {
setResponsePage(new MyPage2(text));
}
 };
form.add(new TextField("text", new PropertyModel(this, "text")));
 form.add(new Button("accept"));
this.add(form);
}
}

<Class MyPage2 does the exact same thing, except it sets MyPage as the
response page.>

When debugging (with a breakpoint in MyPage's constructor), every time a new
page is instanciated, I see that the old instances of that page remains in
memory. Using the "All references" feature I "walked" through the
reference-path, and I reached a weakReference to this page from a
"SerializedPagesCache$SerializedPageWithSession" instance (I had to stop
there because it was driving me crazy). (Of course I have no idea whether
this is normal or not, I'm just giving more info)

Anyway, can anyone tell me what's wrong? Or is this a expected behavior and
sometime later this old instances will be eliminated from the jvm?

Thanks in advance,

Esteban

Re: Old instances of a page remain in memory (apparently) forever

Posted by Fernando Wermus <fe...@gmail.com>.
If you run System.gc(),  you are recommended to  jvm to run the garbarge.
Anyway, It is not mandatory to do it.

On Thu, Sep 24, 2009 at 12:56 AM, Esteban Ignacio Masoero <
emasoero@getsense.com.ar> wrote:

> Thanks for the quick answer!
> After doing some exhaustive testing, I've just found out that, just before
> seeing your answer. The problem was that it wasn't until the 20th instance
> that finally the garbage collector decided to free up some memmory (I tried
> calling it explicitly but apparently the memmory wasn't too occupied so it
> did nothing).
> On Thu, Sep 24, 2009 at 12:14 AM, Igor Vaynberg <igor.vaynberg@gmail.com
> >wrote:
>
> > the instances are held in memory until the jvm runs the garbage
> collector.
> >
> > -igor
> >
> > On Wed, Sep 23, 2009 at 8:09 PM, Esteban Ignacio Masoero
> > <em...@getsense.com.ar> wrote:
> > > Hi:
> > > I'm not sure whether this behavior is normal or not, so I'm going to
> > > describe it and I hope someone can tell me if I'm doing something wrong
> > or
> > > if there's just nothing wrong!
> > >
> > > In my app I found out that each time a request is made, old instances
> of
> > a
> > > page remain in memory, and get accumulated in time (I noticed this
> > behavior
> > > by looking at the "All instances" feature from eclipse debug's
> > perspective).
> > > I searched the code for bad practices like anonyomus Model classes, but
> I
> > > didn't find those kind of thins. So finally I created a new simple
> > project
> > > to test whether this behaviour repeated there too, and I found out that
> > it
> > > did!
> > >
> > > Here's the new simple project code (wicket 1.3.5, tomcat 6, eclipse
> > > galileo):
> > >
> > > public class MyApp extends WebApplication {
> > > @Override
> > >  public Class getHomePage() {
> > > return MyPage.class;
> > > }
> > > }
> > >
> > > public class MyPage extends WebPage {
> > > private String text;
> > > public MyPage() {
> > >  this("<notext>");
> > > }
> > > public MyPage(String textt) {
> > >  super();
> > > this.text = textt;
> > > Form form = new Form("form"){
> > >  private static final long serialVersionUID = -3566834353426372805L;
> > > @Override
> > >  protected void onSubmit() {
> > > setResponsePage(new MyPage2(text));
> > > }
> > >  };
> > > form.add(new TextField("text", new PropertyModel(this, "text")));
> > >  form.add(new Button("accept"));
> > > this.add(form);
> > > }
> > > }
> > >
> > > <Class MyPage2 does the exact same thing, except it sets MyPage as the
> > > response page.>
> > >
> > > When debugging (with a breakpoint in MyPage's constructor), every time
> a
> > new
> > > page is instanciated, I see that the old instances of that page remains
> > in
> > > memory. Using the "All references" feature I "walked" through the
> > > reference-path, and I reached a weakReference to this page from a
> > > "SerializedPagesCache$SerializedPageWithSession" instance (I had to
> stop
> > > there because it was driving me crazy). (Of course I have no idea
> whether
> > > this is normal or not, I'm just giving more info)
> > >
> > > Anyway, can anyone tell me what's wrong? Or is this a expected behavior
> > and
> > > sometime later this old instances will be eliminated from the jvm?
> > >
> > > Thanks in advance,
> > >
> > > Esteban
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>



-- 
Fernando Wermus.

www.linkedin.com/in/fernandowermus

Re: Old instances of a page remain in memory (apparently) forever

Posted by Esteban Ignacio Masoero <em...@getsense.com.ar>.
Thanks for the quick answer!
After doing some exhaustive testing, I've just found out that, just before
seeing your answer. The problem was that it wasn't until the 20th instance
that finally the garbage collector decided to free up some memmory (I tried
calling it explicitly but apparently the memmory wasn't too occupied so it
did nothing).
On Thu, Sep 24, 2009 at 12:14 AM, Igor Vaynberg <ig...@gmail.com>wrote:

> the instances are held in memory until the jvm runs the garbage collector.
>
> -igor
>
> On Wed, Sep 23, 2009 at 8:09 PM, Esteban Ignacio Masoero
> <em...@getsense.com.ar> wrote:
> > Hi:
> > I'm not sure whether this behavior is normal or not, so I'm going to
> > describe it and I hope someone can tell me if I'm doing something wrong
> or
> > if there's just nothing wrong!
> >
> > In my app I found out that each time a request is made, old instances of
> a
> > page remain in memory, and get accumulated in time (I noticed this
> behavior
> > by looking at the "All instances" feature from eclipse debug's
> perspective).
> > I searched the code for bad practices like anonyomus Model classes, but I
> > didn't find those kind of thins. So finally I created a new simple
> project
> > to test whether this behaviour repeated there too, and I found out that
> it
> > did!
> >
> > Here's the new simple project code (wicket 1.3.5, tomcat 6, eclipse
> > galileo):
> >
> > public class MyApp extends WebApplication {
> > @Override
> >  public Class getHomePage() {
> > return MyPage.class;
> > }
> > }
> >
> > public class MyPage extends WebPage {
> > private String text;
> > public MyPage() {
> >  this("<notext>");
> > }
> > public MyPage(String textt) {
> >  super();
> > this.text = textt;
> > Form form = new Form("form"){
> >  private static final long serialVersionUID = -3566834353426372805L;
> > @Override
> >  protected void onSubmit() {
> > setResponsePage(new MyPage2(text));
> > }
> >  };
> > form.add(new TextField("text", new PropertyModel(this, "text")));
> >  form.add(new Button("accept"));
> > this.add(form);
> > }
> > }
> >
> > <Class MyPage2 does the exact same thing, except it sets MyPage as the
> > response page.>
> >
> > When debugging (with a breakpoint in MyPage's constructor), every time a
> new
> > page is instanciated, I see that the old instances of that page remains
> in
> > memory. Using the "All references" feature I "walked" through the
> > reference-path, and I reached a weakReference to this page from a
> > "SerializedPagesCache$SerializedPageWithSession" instance (I had to stop
> > there because it was driving me crazy). (Of course I have no idea whether
> > this is normal or not, I'm just giving more info)
> >
> > Anyway, can anyone tell me what's wrong? Or is this a expected behavior
> and
> > sometime later this old instances will be eliminated from the jvm?
> >
> > Thanks in advance,
> >
> > Esteban
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Old instances of a page remain in memory (apparently) forever

Posted by Marcelo Fukushima <ta...@gmail.com>.
you can check the javadoc for WeakReference, but basically
WeakReferences hold the reference until a full gc occurs

On Thu, Sep 24, 2009 at 12:14 AM, Igor Vaynberg <ig...@gmail.com> wrote:
> the instances are held in memory until the jvm runs the garbage collector.
>
> -igor
>
> On Wed, Sep 23, 2009 at 8:09 PM, Esteban Ignacio Masoero
> <em...@getsense.com.ar> wrote:
>> Hi:
>> I'm not sure whether this behavior is normal or not, so I'm going to
>> describe it and I hope someone can tell me if I'm doing something wrong or
>> if there's just nothing wrong!
>>
>> In my app I found out that each time a request is made, old instances of a
>> page remain in memory, and get accumulated in time (I noticed this behavior
>> by looking at the "All instances" feature from eclipse debug's perspective).
>> I searched the code for bad practices like anonyomus Model classes, but I
>> didn't find those kind of thins. So finally I created a new simple project
>> to test whether this behaviour repeated there too, and I found out that it
>> did!
>>
>> Here's the new simple project code (wicket 1.3.5, tomcat 6, eclipse
>> galileo):
>>
>> public class MyApp extends WebApplication {
>> @Override
>>  public Class getHomePage() {
>> return MyPage.class;
>> }
>> }
>>
>> public class MyPage extends WebPage {
>> private String text;
>> public MyPage() {
>>  this("<notext>");
>> }
>> public MyPage(String textt) {
>>  super();
>> this.text = textt;
>> Form form = new Form("form"){
>>  private static final long serialVersionUID = -3566834353426372805L;
>> @Override
>>  protected void onSubmit() {
>> setResponsePage(new MyPage2(text));
>> }
>>  };
>> form.add(new TextField("text", new PropertyModel(this, "text")));
>>  form.add(new Button("accept"));
>> this.add(form);
>> }
>> }
>>
>> <Class MyPage2 does the exact same thing, except it sets MyPage as the
>> response page.>
>>
>> When debugging (with a breakpoint in MyPage's constructor), every time a new
>> page is instanciated, I see that the old instances of that page remains in
>> memory. Using the "All references" feature I "walked" through the
>> reference-path, and I reached a weakReference to this page from a
>> "SerializedPagesCache$SerializedPageWithSession" instance (I had to stop
>> there because it was driving me crazy). (Of course I have no idea whether
>> this is normal or not, I'm just giving more info)
>>
>> Anyway, can anyone tell me what's wrong? Or is this a expected behavior and
>> sometime later this old instances will be eliminated from the jvm?
>>
>> Thanks in advance,
>>
>> Esteban
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
http://mapsdev.blogspot.com/
Marcelo Takeshi Fukushima

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Old instances of a page remain in memory (apparently) forever

Posted by Igor Vaynberg <ig...@gmail.com>.
the instances are held in memory until the jvm runs the garbage collector.

-igor

On Wed, Sep 23, 2009 at 8:09 PM, Esteban Ignacio Masoero
<em...@getsense.com.ar> wrote:
> Hi:
> I'm not sure whether this behavior is normal or not, so I'm going to
> describe it and I hope someone can tell me if I'm doing something wrong or
> if there's just nothing wrong!
>
> In my app I found out that each time a request is made, old instances of a
> page remain in memory, and get accumulated in time (I noticed this behavior
> by looking at the "All instances" feature from eclipse debug's perspective).
> I searched the code for bad practices like anonyomus Model classes, but I
> didn't find those kind of thins. So finally I created a new simple project
> to test whether this behaviour repeated there too, and I found out that it
> did!
>
> Here's the new simple project code (wicket 1.3.5, tomcat 6, eclipse
> galileo):
>
> public class MyApp extends WebApplication {
> @Override
>  public Class getHomePage() {
> return MyPage.class;
> }
> }
>
> public class MyPage extends WebPage {
> private String text;
> public MyPage() {
>  this("<notext>");
> }
> public MyPage(String textt) {
>  super();
> this.text = textt;
> Form form = new Form("form"){
>  private static final long serialVersionUID = -3566834353426372805L;
> @Override
>  protected void onSubmit() {
> setResponsePage(new MyPage2(text));
> }
>  };
> form.add(new TextField("text", new PropertyModel(this, "text")));
>  form.add(new Button("accept"));
> this.add(form);
> }
> }
>
> <Class MyPage2 does the exact same thing, except it sets MyPage as the
> response page.>
>
> When debugging (with a breakpoint in MyPage's constructor), every time a new
> page is instanciated, I see that the old instances of that page remains in
> memory. Using the "All references" feature I "walked" through the
> reference-path, and I reached a weakReference to this page from a
> "SerializedPagesCache$SerializedPageWithSession" instance (I had to stop
> there because it was driving me crazy). (Of course I have no idea whether
> this is normal or not, I'm just giving more info)
>
> Anyway, can anyone tell me what's wrong? Or is this a expected behavior and
> sometime later this old instances will be eliminated from the jvm?
>
> Thanks in advance,
>
> Esteban
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org