java.lang.OutOfMemoryError: PermGen when using groovy scripts

Solution Unverified - Updated

Environment

  • JBoss Enterprise Application Platform (EAP)
  • Groovy

Issue

  • We exhaust our PermGen space and see thousands of Script# classes loaded by groovy.lang.GroovyClassLoader$InnerLoaders. The heap dump shows them retained in GroovyClassLoader's classCache:
Class Name                                                                                                          | Ref. Objects | Shallow Heap | Ref. Shallow Heap | Retained Heap 
---------------------------------------------------------------------------------------------------------------------------------------------------------
gs groovy.lang.GroovyShell @ 0x707b3bbe0                                              |       30,682 |            56 |         6,381,856 |            88 
 '- loader groovy.lang.GroovyClassLoader @ 0x707b3bf20                    |       30,682 |          192 |         6,381,856 |     1,999,032 
    '- classCache java.util.HashMap @ 0x707b3c388                                  |       30,682 |            72 |         6,381,856 |     1,997,120 
---------------------------------------------------------------------------------------------------------------------------------------------------------

Resolution

  • Increase the Perm Gen size to meet demands of the growing cache.
  • Clear the growing classCache. Calling GroovyClassLoader.clearCache should clear its cache and it looks like that would be called through GroovyShell.resetLoadedClasses.
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.