AccessClassLoader cleanup

77 views
Skip to first unread message

Jim Marino

unread,
Feb 5, 2013, 10:26:19 AM2/5/13
to reflecta...@googlegroups.com
Hi,

Congrats on a really nice, clean, and useful library.

In looking at the source, I noticed that a static cache of AccessClassLoaders are maintained in AccessClassLoader. However, I couldn't find a mechanism for cleaning those up when the parent classloader is removed from the JVM. For example, I have a server environment where user applications are deployed and undeployed. An application is associated with a classloader so when the application is undeployed, all references to the classloader must be removed for it to be properly garbage collected. 

I did not see a mechanism for achieving this but perhaps I missed something?

If there isn't, perhaps the cache could be changed to a ConcurrentHashMap keyed by parent classloader and an addition method added to AccessClassLoader such as:

void clearCache(ClassLoader parent)


Jim

Nate

unread,
Feb 5, 2013, 10:43:25 AM2/5/13
to reflecta...@googlegroups.com
Hi Jim,

Thanks. :) Does this method I just added meet your needs?

https://code.google.com/p/reflectasm/source/diff?spec=svn49&r=49&format=side&path=/trunk/src/com/esotericsoftware/reflectasm/AccessClassLoader.java

-Nate


--
--
You received this message because you are subscribed to the "reflectasm-users" group.
http://groups.google.com/group/reflectasm-users
---
You received this message because you are subscribed to the Google Groups "reflectasm-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reflectasm-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jim Marino

unread,
Feb 5, 2013, 7:38:44 PM2/5/13
to reflecta...@googlegroups.com
Thanks! That was fast. I have two quick questions:

1. Is there a timeframe for publishing a release to Maven central with this change so we can add it as a dependency to our project (Fabric3)?

2. Is there a reason the cache is an ArrayList as opposed to a ConcurrentHashMap?

Thanks again for the speedy response.

Jim 


On Tue, Feb 5, 2013 at 4:26 PM, Jim Marino <jim.m...@gmail.com> wrote:

--

Nate

unread,
Feb 5, 2013, 9:06:31 PM2/5/13
to reflecta...@googlegroups.com
Hi Jim,


On Wed, Feb 6, 2013 at 1:38 AM, Jim Marino <jim.m...@gmail.com> wrote:
Thanks! That was fast. I have two quick questions:

1. Is there a timeframe for publishing a release to Maven central with this change so we can add it as a dependency to our project (Fabric3)?

I don't handle publishing to Maven central myself, but I think it can be done pretty quick. It would be great if you tested the fix works for you, then I can do a release.
 

2. Is there a reason the cache is an ArrayList as opposed to a ConcurrentHashMap?

I doubt there will be many classloaders in the list, I doubt they will be removed very often, and keeping it as an ArrayList meant the new functionality is only additive and can't break any existing code. If it becomes a bottleneck we can always change it.

-Nate

Jim Marino

unread,
Feb 6, 2013, 3:03:12 AM2/6/13
to reflecta...@googlegroups.com
Hi Nate,

Comments inline.

Thanks again,
Jim



On Wed, Feb 6, 2013 at 3:06 AM, Nate <nathan...@gmail.com> wrote:
Hi Jim,


On Wed, Feb 6, 2013 at 1:38 AM, Jim Marino <jim.m...@gmail.com> wrote:
Thanks! That was fast. I have two quick questions:

1. Is there a timeframe for publishing a release to Maven central with this change so we can add it as a dependency to our project (Fabric3)?

I don't handle publishing to Maven central myself, but I think it can be done pretty quick. It would be great if you tested the fix works for you, then I can do a release.
 

Sure. It may take me about a week as I need to integrate with our codebase. I'll follow-up as soon as it is done.

Re Maven, I believe Sonatype will sync open source projects to Maven central directly if you don't already do this via another mechanism. I know reflectasm is already in Maven central so perhaps you are using another mechanism. I'm happy to help with this if needed.
  

2. Is there a reason the cache is an ArrayList as opposed to a ConcurrentHashMap?

I doubt there will be many classloaders in the list, I doubt they will be removed very often, and keeping it as an ArrayList meant the new functionality is only additive and can't break any existing code. If it becomes a bottleneck we can always change it.


That's reasonable. In our case I don't think it will be a bottleneck as this will be done on app startup time and not request processing.

 
-Nate

Martin Grotzke

unread,
Feb 6, 2013, 1:48:15 AM2/6/13
to reflecta...@googlegroups.com

I can release to maven central as always.

Cheers,
Martin

Martin Grotzke

unread,
Feb 6, 2013, 3:30:27 PM2/6/13
to reflecta...@googlegroups.com
On 02/06/2013 09:03 AM, Jim Marino wrote:
> Re Maven, I believe Sonatype will sync open source projects to Maven
> central directly if you don't already do this via another mechanism. I
> know reflectasm is already in Maven central so perhaps you are using
> another mechanism. I'm happy to help with this if needed.

As Nate is not a big maven fan I did releases of reflectasm and kryo to
sonatypes oss repo, so we it already set up.

I just deployed the latest version (r49) as 1.08-SNAPSHOT to
https://oss.sonatype.org/content/repositories/snapshots/

Cheers,
Martin


>
>
>
> 2. Is there a reason the cache is an ArrayList as opposed to a
> ConcurrentHashMap?
>
>
> I doubt there will be many classloaders in the list, I doubt they
> will be removed very often, and keeping it as an ArrayList meant the
> new functionality is only additive and can't break any existing
> code. If it becomes a bottleneck we can always change it.
>
>
> That's reasonable. In our case I don't think it will be a bottleneck as
> this will be done on app startup time and not request processing.
>
>
>
> -Nate
>
>
> --
> --
> You received this message because you are subscribed to the
> "reflectasm-users" group.
> http://groups.google.com/group/reflectasm-users
> ---
> You received this message because you are subscribed to the Google
> Groups "reflectasm-users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to reflectasm-use...@googlegroups.com
> <mailto:reflectasm-users%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
> --
> --
> You received this message because you are subscribed to the
> "reflectasm-users" group.
> http://groups.google.com/group/reflectasm-users
> ---
> You received this message because you are subscribed to the Google
> Groups "reflectasm-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to reflectasm-use...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
inoio gmbh - http://inoio.de
Schulterblatt 36, 20357 Hamburg
Amtsgericht Hamburg, HRB 123031
Geschäftsführer: Dennis Brakhane, Martin Grotzke, Ole Langbehn

Jim Marino

unread,
Feb 6, 2013, 6:02:57 PM2/6/13
to reflecta...@googlegroups.com
Great! Thanks.

Jim

Tumi

unread,
Dec 17, 2013, 8:02:14 PM12/17/13
to reflecta...@googlegroups.com
Hey there, you are right, and I'm afraid that the PermGenmemory leak is still there, because of the strong references to class loaders. I filled an explanation and a proposed patch :-) to use WeakReferences and solve the problem (unit test added)

Here: http://code.google.com/p/reflectasm/issues/detail?id=18

Cheers!
Reply all
Reply to author
Forward
0 new messages