Reputation: 28757
We have an application that generates thousands of Java ClassLoaders and classes, before letting them be garbage collected. We are pretty sure there is no class loader leak, but we are getting permgen errors (and even if there is, this question is orthogonal to any potential leak).
Is there any way of specifying that certain ClassLoaders and their loaded classes are placed in the heap rather than in perm gen?
We are using the Oracle JDK Java 6 on Linux.
Edit: Looks like Java 8 will no longer have PermGen. It will be replaced by Metaspace.
http://java.dzone.com/articles/java-8-permgen-metaspace
Upvotes: 0
Views: 370
Reputation: 719307
Is there any way of specifying that certain ClassLoaders and their loaded classes are placed in the heap rather than in perm gen?
AFAIK, there is no way to do that. AFAIK, the permgen allocation happens deep in the JVM runtime where you can't get at it. (I don't think that the classloader itself is in permgen. I think it is just certain of the JVM's internal data structures that represent the classes and their code.)
If your application really has to work that way, I think you have no choice but to make permgen large enough. (Obviously, you should also check that the real problem isn't a permgen leak.)
However, it strikes me that your application's architecture is rather strange if it needs to generate lots of classes and class loaders. I'd look to see if what it is doing couldn't be done another way.
Upvotes: 1
Reputation: 308968
Of course you're getting perm gen errors - that's where class loaders put classes. What would you expect?
You can map them into byte buffers, like Java NIO does it, but they don't go on the heap.
You ought to try increasing your perm gen size before taking extraordinary measures. How much perm gen space do you need? Profile it using Visual VM and see.
Upvotes: 2