I'm not sure about this assertion myself.  The GC is capable of freeing
up cyclical references.  The problem comes when the container class
loaders have a reference to an application class.  I don't believe
singletons cause this problem on their own as they should be cleaned up
when the application class loader goes out of scope.

Basically you get this layout

System Class loader
Common Class loader
Application Class loader (one per web app) 

When the webapp is undeployed the container deletes all references to
the application class loader and expects the GC to clean it up.  This
can fail to happen if something in the System/Common class loaders are
holding references to ANYTHING in the application class loader
(object/class/whatever).

Read the article linked below
(http://opensource.atlassian.com/confluence/spring/pages/viewpage.action
?pageId=2669) for some common causes and a better explanation of the
problem.

Cheers.

Mike.

-----Original Message-----
From: Leon Rosenberg [mailto:[EMAIL PROTECTED] 
Sent: 16 February 2007 16:40
To: Tomcat Users List
Subject: Re: PermGen space [ot]

separate the singleton itself and the factory.

in the previous example:

 public class ASingletonFactory{
    private static ASingletonImpl instance = new ASingletonImpl();
    public static  AsingletonImpl getInstance(){
       return instance;
   }
}

 public class ASingletonImpl{
    ASingletonImpl(){
    }
    ///real code here
 }


regards
Leon

On 2/16/07, Jason Pyeron <[EMAIL PROTECTED]> wrote:
> So how should one write their singleton?
>
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> -                                                               -
> - Jason Pyeron                      PD Inc. http://www.pdinc.us -
> - Sr. Consultant                    10 West 24th Street #100    -
> - +1 (443) 269-1555 x333            Baltimore, Maryland 21218   -
> -                                                               -
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>
> This message is for the designated recipient only and may contain 
> privileged, proprietary, or otherwise private information. If you have

> received it in error, purge the message from your system and notify 
> the sender immediately.  Any other use of the email by you is 
> prohibited.
>
>
> -----Original Message-----
> From: Leon Rosenberg [mailto:[EMAIL PROTECTED]
> Sent: Friday, February 16, 2007 11:33
> To: Tomcat Users List
> Subject: Re: PermGen space
>
> something like this:
>
> public class ASingletonImpl{
>    private static ASingletonImpl instance;
>    public synchronized AsingletonImpl getInstance(){
>       if (instance==null){
>          instance = new ASingletonImpl();
>       }
>       return instance;
>    }
>
>    ///real code here
> }
>
> The problem is the cyclic dependence between the Class object, the 
> ASingletonImpl object and the according ClassLoader. This way nothing 
> can be freed by the gc.
>
> regards
> Leon
>
>
> On 2/16/07, Jiang, Peiyun <[EMAIL PROTECTED]> wrote:
> > Just curious, can you elaborate on badly programmed singletons?
> >
> > Thanks.
> >
> > Peiyun
> >
> > -----Original Message-----
> > From: Leon Rosenberg [mailto:[EMAIL PROTECTED]
> > Sent: February 16, 2007 11:08 AM
> > To: Tomcat Users List
> > Subject: Re: PermGen space
> >
> >
> > The typical problem here are badly programmed singletons. Do you
have any?
> >
> > regards
> > Leon
> >
> > On 2/16/07, Davide Romanini <[EMAIL PROTECTED]> wrote:
> > > I'm too have this problem, it arises because for some reason the 
> > > Tomcat WebAppClassloader cannot be garbage collected after 
> > > undeploy. I made a lot of tests and didn't find any solution, also

> > > very simple and small webapps, when loaded/unloaded frequently, 
> > > caused the problem... :-(
> > >
> >
> > --------------------------------------------------------------------
> > - To start a new topic, e-mail: users@tomcat.apache.org To 
> > unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> > --------------------------------------------------------------------
> > - To start a new topic, e-mail: users@tomcat.apache.org To 
> > unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, 
> e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, 
> e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe,
e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



 This e-mail is bound by the terms and conditions described at 
http://www.subexazure.com/mail-disclaimer.html


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to