[ 
https://issues.apache.org/jira/browse/GROOVY-3476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149585#comment-18149585
 ] 

ASF GitHub Bot commented on GROOVY-3476:
----------------------------------------

daniellansun opened a new pull request, #3347:
URL: https://github.com/apache/groovy/pull/3347

   https://issues.apache.org/jira/browse/GROOVY-3476
   
   `groovy -l` compiled the listener script before every `accept`. Each 
compilation defined a new class, so the number of loaded classes grew with 
every connection.
   
   This change compiles the class once, and again only when a file or URL 
source's bytes change, and gives each connection its own script instance 
through `InvokerHelper.createScript` and the shell binding. The script for a 
connection is read and compiled after `accept()`, so an edit made while the 
listener is waiting is what that connection runs. Inline text is compiled once. 
A failed read or compile is reported, that client is closed, and the listener 
keeps accepting.
   
   Class-level state (static fields, static initializers, and class-level 
meta-class changes) survives across connections; instance fields still reset 
because each connection gets a new instance.
   
   `close()` sets a volatile `closing` flag before it closes the listening 
socket, so the `SocketException` from unblocking `accept()` is not printed. If 
`close()` runs before the socket is published, `run()` returns after the bind 
and try-with-resources closes the socket. The command-line manual 
(`tools-groovy.adoc`) now matches this behavior.
   
   Coverage is in `GroovySocketServerTest`.
   




> 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)

Reply via email to