Skip to content

Avoid PermGen leak#54

Closed
elrodro83 wants to merge 1 commit intocglib:masterfrom
elrodro83:patch-1
Closed

Avoid PermGen leak#54
elrodro83 wants to merge 1 commit intocglib:masterfrom
elrodro83:patch-1

Conversation

@elrodro83
Copy link
Contributor

The key object put in the cache may be an instance of a dynamically generated class that references an application classloader. That reference causes said classloader to not be available for garbage collection, thus leaking the PermGen with old classes when that classloader is not needed anymore. This is mostly experienced in application restart scenarios, where each application has its own classloader managed in a long-lived container.

Attached is an exceprt from a heap dump that shoes the reference to the classloader that causes the issue:

screen shot 2015-11-10 at 11 00 50 am

This is a rework of #49
Icludes the tests added in #50

The change is essentially flattening the key ised in the cache to a string, which contains the fully qualified types of the defined classes.

@elrodro83 elrodro83 mentioned this pull request Nov 14, 2015
@vlsi
Copy link
Contributor

vlsi commented Nov 14, 2015

Why do you think it is better than #50?
#50 would likely be faster (it would skip string concatenation) and it would be more debuggable (one would see proper values in debugger & heap dump)

@vlsi
Copy link
Contributor

vlsi commented Nov 14, 2015

Here are the measurements (you can reproduce via #55)

#54:

Benchmark                                        Mode  Cnt     Score     Error   Units
BeansBenchmark.newInstance                       avgt    5  3164,626 ± 147,531   ns/op
BeansBenchmark.newInstance:·gc.alloc.rate.norm   avgt    5  3128,001 ±   0,001    B/op

#50:

Benchmark                                        Mode  Cnt     Score     Error   Units
BeansBenchmark.newInstance                       avgt    5  2607,519 ± 195,528   ns/op
BeansBenchmark.newInstance:·gc.alloc.rate.norm   avgt    5  1272,001 ±   0,001    B/op

As you see, additional toString allocates like 3128-1272=1856 bytes per call of Beans.newInstance(Beans.class)
toString is slower as well

@elrodro83
Copy link
Contributor Author

That's okay. I just wanted to keep this as an option. Thanks for the bechmark!

@vlsi
Copy link
Contributor

vlsi commented Nov 16, 2015

Will try another approach with Customizer/FieldTypeCustomizer classes: Map<Class, List<KeyFactoryCustomizer>>

raphw pushed a commit that referenced this pull request Feb 4, 2016
To the best of my knowledge, this looks like a good solution given the bounds of the current implementation. I favour this solution over #54, it seems like the cleaner solution and it is benchmarked.
@raphw
Copy link
Member

raphw commented Feb 4, 2016

This is fixed by #50.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants