You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by Kevan Miller <ke...@gmail.com> on 2005/11/11 17:06:29 UTC

Workaround for URLJarFile memory leak

As I mentioned previously, there is a memory leak of URLJarFile instances in
Geronimo. The problem is caused by
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4167874 --
sun.net.www.protocol.jar.JarFileFactory will hold onto strong references to
all URLJarFile instances. So URLJarFiles can never be GCed. This means that
for every deploy/undeploy of an application, you'll leak URLJarFiles.

The problem can be avoided by calling URLConnection.setDefaultUseCaches(false);
This will turn off the caching in JarFileFactory. I added a call to
setDefaultUseCaches() to DeploymentUtil.readAll() and verified that Geronimo
no longer leaks URLJarFile instances.

Note that setDefaultUseCaches(false) is a "global" setting. So it affects
the entire runtime. URLConnection.setUseCaches(false) does not fix the
problem. Since, there is the potential for a performance impact, I thought
I'd advertise the issue. I don't see any usages within Geronimo code where
this would cause major problems. However, there may be issues which I'm not
realizing...

Comments? Barring concerns, I'll raise a Jira and post a patch.

--kevan

Re: Workaround for URLJarFile memory leak

Posted by Kevan Miller <ke...@gmail.com>.
Yeah, I'd thought about putting it in Daemon (I probably would have
forgotten/not known about CommandLine). And what you propose is the correct
solution, I think. By delaying until Deploy time, we leak ~ 20 URLJarFiles
(I don't know how much memory) and it better guards us for any future uses
of URLJarFile. Creating a "dummy" URL to set the UseCaches default just felt
like such a <hack>. Putting it in DeploymentUtil put the hack close to where
it was needed -- I was somehow comforted by this...

I'll work up the CommandLine and Daemon changes...

--kevan

On 11/11/05, Dain Sundstrom <da...@iq80.com> wrote:
>
> Maybe we should put this in the CommandLine class in the static block
> at the top, and in Daemon line 153. Basically before we initialize
> the logging system. These are the places where we put global
> initialization code. Actually now that I think about it, it would be
> nice to have a single place we put this type of static global
> initialization code.
>
> -dain
>
> On Nov 11, 2005, at 8:50 AM, Jeff Genender wrote:
>
> > Comments????
> >
> > How about nice work! ;-)
> >
> > I don't see any issues. If the others don't see problems, I will
> > be happy to apply your patch...just assign it to me.
> >
> > Jeff
> >
> > Kevan Miller wrote:
> >> As I mentioned previously, there is a memory leak of URLJarFile
> >> instances in
> >> Geronimo. The problem is caused by
> >> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4167874 --
> >> sun.net.www.protocol.jar.JarFileFactory will hold onto strong
> >> references to
> >> all URLJarFile instances. So URLJarFiles can never be GCed. This
> >> means that
> >> for every deploy/undeploy of an application, you'll leak URLJarFiles.
> >> The problem can be avoided by calling
> >> URLConnection.setDefaultUseCaches(false);
> >> This will turn off the caching in JarFileFactory. I added a call to
> >> setDefaultUseCaches() to DeploymentUtil.readAll() and verified
> >> that Geronimo
> >> no longer leaks URLJarFile instances.
> >> Note that setDefaultUseCaches(false) is a "global" setting. So it
> >> affects
> >> the entire runtime. URLConnection.setUseCaches(false) does not fix
> >> the
> >> problem. Since, there is the potential for a performance impact, I
> >> thought
> >> I'd advertise the issue. I don't see any usages within Geronimo
> >> code where
> >> this would cause major problems. However, there may be issues
> >> which I'm not
> >> realizing...
> >> Comments? Barring concerns, I'll raise a Jira and post a patch.
> >> --kevan
>
>

Re: Workaround for URLJarFile memory leak

Posted by Dain Sundstrom <da...@iq80.com>.
Maybe we should put this in the CommandLine class in the static block  
at the top, and in Daemon line 153.  Basically before we initialize  
the logging system.  These are the places where we put global  
initialization code.  Actually now that I think about it, it would be  
nice to have a single place we put this type of static global  
initialization code.

-dain

On Nov 11, 2005, at 8:50 AM, Jeff Genender wrote:

> Comments????
>
> How about nice work! ;-)
>
> I don't see any issues.  If the others don't see problems, I will  
> be happy to apply your patch...just assign it to me.
>
> Jeff
>
> Kevan Miller wrote:
>> As I mentioned previously, there is a memory leak of URLJarFile  
>> instances in
>> Geronimo. The problem is caused by
>> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4167874 --
>> sun.net.www.protocol.jar.JarFileFactory will hold onto strong  
>> references to
>> all URLJarFile instances. So URLJarFiles can never be GCed. This  
>> means that
>> for every deploy/undeploy of an application, you'll leak URLJarFiles.
>> The problem can be avoided by calling  
>> URLConnection.setDefaultUseCaches(false);
>> This will turn off the caching in JarFileFactory. I added a call to
>> setDefaultUseCaches() to DeploymentUtil.readAll() and verified  
>> that Geronimo
>> no longer leaks URLJarFile instances.
>> Note that setDefaultUseCaches(false) is a "global" setting. So it  
>> affects
>> the entire runtime. URLConnection.setUseCaches(false) does not fix  
>> the
>> problem. Since, there is the potential for a performance impact, I  
>> thought
>> I'd advertise the issue. I don't see any usages within Geronimo  
>> code where
>> this would cause major problems. However, there may be issues  
>> which I'm not
>> realizing...
>> Comments? Barring concerns, I'll raise a Jira and post a patch.
>> --kevan


Re: Workaround for URLJarFile memory leak

Posted by Jeff Genender <jg...@savoirtech.com>.
Comments????

How about nice work! ;-)

I don't see any issues.  If the others don't see problems, I will be 
happy to apply your patch...just assign it to me.

Jeff

Kevan Miller wrote:
> As I mentioned previously, there is a memory leak of URLJarFile instances in
> Geronimo. The problem is caused by
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4167874 --
> sun.net.www.protocol.jar.JarFileFactory will hold onto strong references to
> all URLJarFile instances. So URLJarFiles can never be GCed. This means that
> for every deploy/undeploy of an application, you'll leak URLJarFiles.
> 
> The problem can be avoided by calling URLConnection.setDefaultUseCaches(false);
> This will turn off the caching in JarFileFactory. I added a call to
> setDefaultUseCaches() to DeploymentUtil.readAll() and verified that Geronimo
> no longer leaks URLJarFile instances.
> 
> Note that setDefaultUseCaches(false) is a "global" setting. So it affects
> the entire runtime. URLConnection.setUseCaches(false) does not fix the
> problem. Since, there is the potential for a performance impact, I thought
> I'd advertise the issue. I don't see any usages within Geronimo code where
> this would cause major problems. However, there may be issues which I'm not
> realizing...
> 
> Comments? Barring concerns, I'll raise a Jira and post a patch.
> 
> --kevan
>