Finalizer Memory Leak

1,532 views
Skip to first unread message

Vojtěch Krása

unread,
Mar 24, 2010, 1:25:23 PM3/24/10
to google...@googlegroups.com
Hi,
 
i have problem on tomcat 6.0 even with clean Wicket+Guice project from http://jweekend.co.uk/dev/LegUp ...
 
tomcat log:
SEVERE: A web application appears to have started a thread named [com.google.inject.internal.Finalizer] but has failed to stop it. This is very likely to create a memory leak.
it seems like an old issue... is there any solutions?

Thanks.

Alen Vrečko

unread,
Mar 25, 2010, 6:11:29 AM3/25/10
to google-guice
The issue is still open http://code.google.com/p/guava-libraries/issues/detail?id=92

indeed there is a memory leak. As workarounds goes I used

o) Thread "unleaker" - basically a ServletContextListener that finds
any
Finalizer Threads and clears the "bad" references. The WebAppCL is
clear to be GCed but the Finalizer thread sticks around until the perm
gen gets full. I don't like it.

o) A custom Guice distribution that has an explicit method to
shutdown. This is what I am currently using.

imho it would not hurt to have an explicit shutdown method in the
official version. Like injector.stopFinalizer(); for those of us who
can't restart-to-redeploy. It's better to have one more method than
one more memory leak.

Cheers
Alen

cowwoc

unread,
Mar 25, 2010, 9:30:18 AM3/25/10
to google...@googlegroups.com

Guice should either provide a shutdown method as a temporary
workaround (to be removed in future releases) or fix the problem
immediately. I don't like the fact that you've chosen to ship the
product with a pretty sizable memory leak and no decent workaround.

Gili

limpb...@gmail.com

unread,
Mar 25, 2010, 11:55:24 AM3/25/10
to google-guice
On Mar 25, 6:30 am, cowwoc <cow...@bbs.darktech.org> wrote:
> [...] I don't like the fact that you've chosen to ship the

> product with a pretty sizable memory leak and no decent workaround.

Umm... the decent workaround is to restart your application when you
redeploy.

Bob Lee

unread,
Mar 25, 2010, 12:13:03 PM3/25/10
to google...@googlegroups.com
+1

I'll fix it eventually. My fix will only work on specific VM's, of course, as it'll depend on private APIs.

Bob 

Vojtěch Krása

unread,
Mar 25, 2010, 6:21:41 PM3/25/10
to google...@googlegroups.com
I tried your FinalizerLeakPatcher, but it does not work. Could you please upload that custom Guice distribution?
Thanks.

2010/3/25 Alen Vrečko <alen_...@yahoo.com>
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.




--
S pozdravem
Vojtěch Krása

Endre Stølsvik

unread,
Mar 25, 2010, 9:11:17 PM3/25/10
to google...@googlegroups.com
Do you mean to restart the entire JVM? 

What is that Finalizer used for?

Endre.

cowwoc

unread,
Mar 25, 2010, 11:49:28 PM3/25/10
to google...@googlegroups.com
On 25/03/2010 12:13 PM, Bob Lee wrote:
On Thu, Mar 25, 2010 at 8:55 AM, je...@swank.ca <limpb...@gmail.com> wrote:
On Mar 25, 6:30 am, cowwoc <cow...@bbs.darktech.org> wrote:
> [...] I don't like the fact that you've chosen to ship the
> product with a pretty sizable memory leak and no decent workaround.

Umm... the decent workaround is to restart your application when you
redeploy.

    This is not a viable solution for debugging web applications. Some servers take over a minute to restart. In the past I had to issue a restart every two runs because I'd run out of memory. This is a huge productivity killer.


+1

I'll fix it eventually. My fix will only work on specific VM's, of course, as it'll depend on private APIs.

    So why not bite the bullet and add a shutdown method? There are plenty of APIs with dispose() methods. Isn't this more reasonable than resorting to complicated voodoo that only works for a subset of your users? Seeing as you work for Google, why not ask Joshua Bloch for advice?

Gili

Stuart McCulloch

unread,
Mar 26, 2010, 4:44:44 PM3/26/10
to google...@googlegroups.com
2010/3/25 Endre Stølsvik <stol...@gmail.com>
Do you mean to restart the entire JVM? 

What is that Finalizer used for?

FYI... that thread is used to clean up references in weak/soft maps
(it comes from the Guice copy of google-collections / guava code)
 



--
Cheers, Stuart

Stuart McCulloch

unread,
Mar 26, 2010, 5:00:49 PM3/26/10
to google...@googlegroups.com

Bob's actually moved to Square (https://squareup.com), but personally I also agree a shutdown method is cleaner.
The downside of a shutdown method is that there's no easy way to stop people using the library after it's shutdown
- of course this is hopefully an edge case, and just means soft/weak references wouldn't be collected until the app
was finished.

Another solution would be to add an OSGi bundle activator class:

   http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleActivator.html

to the internal package with a Bundle-Activator manifest entry pointing to it - it would mean Guice would need to
build against the OSGi API jar, but clients would not need OSGi. The activator class would sit unnoticed in the
internal package by most people as they'd never load it.

But if Guice was installed onto an OSGi capable app-server like GlassFish then stopping the Guice bundle would
notify the activator which could then shutdown the Finalizer thread without needing any special JVM knowledge or
reflection tricks. This may be a good compromise to exposing a public shutdown method...

Just my 2 sen.

Gili

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

--
Cheers, Stuart

Eelco Hillenius

unread,
Mar 26, 2010, 5:22:33 PM3/26/10
to google...@googlegroups.com
>This may be a good compromise to exposing a public
> shutdown method...

I would find that helpful too. It doesn't have to be either/ or either, right?

Eelco

Stuart McCulloch

unread,
Mar 26, 2010, 5:34:09 PM3/26/10
to google...@googlegroups.com

sure, just enumerating the options...
 
Eelco

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

--
Cheers, Stuart

Alen Vrečko

unread,
May 2, 2010, 1:35:06 PM5/2/10
to google-guice
One more option is to refacture the code so it doesn't use weak maps.
I've wrote about it here http://code.google.com/p/google-guice/issues/detail?id=288.

Cheers
Alen

On Mar 26, 11:34 pm, Stuart McCulloch <mccu...@gmail.com> wrote:
> On 26 March 2010 14:22, Eelco Hillenius <eelco.hillen...@gmail.com> wrote:
>
> > >This may be a good compromise to exposing a public
> > > shutdown method...
>
> > I would find that helpful too. It doesn't have to be either/ or either,
> > right?
>
> sure, just enumerating the options...
>
> > Eelco
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "google-guice" group.
> > To post to this group, send email to google...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-guice...@googlegroups.com<google-guice%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages