Skip to content

ScriptedConfiguration.release() leaves the published engine's customizer class registered, pinning one GroovyClassLoader per release #154

Closed

Description

@vharseko

ScriptedConfiguration.release() drops the published engine but never unregisters the class of its customizer script. The REST, CREST and SSH configurations register an ExpandoMetaClass on that class in createCustomizerScript (customizerClass.metaClass.customize << {…}: ScriptedRESTConfiguration.groovy:189, ScriptedCRESTConfiguration.groovy:224, SSHConfiguration.groovy:387). On Groovy 2.4.21 a registered metaclass stays reachable from the global ClassInfo set, so it keeps the customizer class alive, and with it:

  • the configuration's own GroovyClassLoader and every script it compiled (ScriptedConfiguration.getGroovyScriptEngine() builds a new loader per configuration);
  • the released configuration itself, which is the owner of the customize closure.

Every facade dispose or configuration change of a REST, CREST or SSH connector therefore leaks one loader. A probe of 50 attempts in the review of #132 found every such loader alive after heap exhaustion, and none when no metaclass was registered.

#132 fixes the same pin for a customizer that fails (InvokerHelper.removeClass in initializeCustomizer()'s catch), because a retry compiles a new class each time. The class of a customizer that succeeded is not covered; the code on master behaves the same.

Proposed fix (from the #132 review): initializeCustomizer() returns the customizer class; getGroovyScriptEngine() keeps it in a field guarded by the configuration's monitor next to the published engine; release() calls InvokerHelper.removeClass on it after the release closure has run, then clears the field.

Test: the stand-in from ScriptedConfigurationTest.testFailedCustomizerClassIsUnregistered with a customizer that succeeds, then configuration.release(), then ClassInfo.getClassInfo(clazz).getStrongMetaClass() is null. It fails without the release() change.

Raised in the review of #132 (#132 (review)).

Activity

  1. added
    bugSomething isn't working
    javaPull requests that update java code
    resource-leakMemory, class-loader, thread or handle leaks
    on Oct 5, 2026
  2. added 2 commits that reference this issue on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingconnector:groovyGroovy connectorconnector:sshSSH connectorjavaPull requests that update java coderesource-leakMemory, class-loader, thread or handle leaks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions