[
https://issues.apache.org/jira/browse/GROOVY-3476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150677#comment-18150677
]
ASF GitHub Bot commented on GROOVY-3476:
----------------------------------------
blackdrag commented on PR #3347:
URL: https://github.com/apache/groovy/pull/3347#issuecomment-7155784577
Oh, why is @daniellansun doing the PR for @jdbeutel had I known I would have
explained in much more detail.
GroovyShell.parseClass essentially delegates to
GroovyClassLoader.parseClass, which will spin up a inner loader, that is then
used to define the class. If nothing is done about it, that class keeps
existing. But GroovyShell has resetLoadedClasses, which will detach the inner
loader from the GroovyClassLoader and GroovyShell. Noe it depends on the usage
of the class if it can be collected. Therefore a simple solution is
```Java
// Compile and execute the script for this connection
Script script = shell.parse(source);
// Handle connection using script
// Once this connection is finished:
shell.resetLoadedClasses();
```
This should avoid the issue 3476 problem. This does not make `groovy -l` a
server able to handle multiple concurrent clients. But I also do not think that
this or effeciently caching the script class is really needed to fix the issue
that was reported. I advise to do a small scope fix and anything else should be
in another issue/PR
> groovy -l constantly loads classes and leaks memory
> ---------------------------------------------------
>
> Key: GROOVY-3476
> URL: https://issues.apache.org/jira/browse/GROOVY-3476
> Project: Groovy
> Issue Type: Bug
> Components: command line processing
> Affects Versions: 1.6.1, 2.1.2
> Environment: Linux, Solaris, and Cygwin, at least
> Reporter: J. David Beutel
> Assignee: Daniel Sun
> Priority: Major
>
> The classes loaded by a -l script keep increasing until the JVM runs out of
> memory. I saw this with a script file, but it also can be demonstrated with
> two command lines:
> {code}
> JAVA_OPTS="-Xmx5m" groovy -l 5000 -e "System.err.println
> java.lang.management.ManagementFactory.classLoadingMXBean.loadedClassCount" &
> groovy -e "while (true) { new Socket('localhost',5000).outputStream << '\n'}"
> {code}
> As a work-around, I used a ServerSocket instead of groovy -l.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)