You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/02/12 20:11:00 UTC
[jira] [Comment Edited] (GROOVY-10918) Memory leak: local variable values are not discarded
[ https://issues.apache.org/jira/browse/GROOVY-10918?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17687622#comment-17687622 ]
Eric Milles edited comment on GROOVY-10918 at 2/12/23 8:10 PM:
---------------------------------------------------------------
What kind of behavior do you get with lambdas? They should match java and do not require creation of Integer parameter and Closure object.
{code:groovy}
import java.util.stream.Collectors
test("W"*(100*1024*1024))
@groovy.transform.CompileStatic
String test(String s) {
s = s.chars().mapToObj(ch -> "X").collect(Collectors.joining())
println s.charAt(0)
s = s.chars().mapToObj(ch -> "Y").collect(Collectors.joining())
println s.charAt(0)
s = s.chars().mapToObj(ch -> "Z").collect(Collectors.joining())
println s.charAt(0)
return s
}
{code}
was (Author: emilles):
What kind of behavior do you get with lambdas? They should match java and do not require creation of Integer parameter and Closure object.
```groovy
import java.util.stream.Collectors
test("W"*(100*1024*1024))
@groovy.transform.CompileStatic
String test(String s) {
s = s.chars().mapToObj(ch -> "X").collect(Collectors.joining())
println s.charAt(0)
s = s.chars().mapToObj(ch -> "Y").collect(Collectors.joining())
println s.charAt(0)
s = s.chars().mapToObj(ch -> "Z").collect(Collectors.joining())
println s.charAt(0)
return s
}
```
> Memory leak: local variable values are not discarded
> ----------------------------------------------------
>
> Key: GROOVY-10918
> URL: https://issues.apache.org/jira/browse/GROOVY-10918
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 4.0.9
> Reporter: Andriy Rysin
> Priority: Major
> Labels: MemoryLeak
> Attachments: TestOOM.groovy, TestOOMIcj.java, TestOOMJ.java, TestOOM_works.groovy, groovy_oom.png
>
>
> When I run the code below with 3 statements with closures inside the method the local var (parameter) values (all 4 of them) are staying in memory.
> I don't see the same problem if I run corresponding Java code with lambdas.
> Run TestOOM.groovy with
> -Xmx600M -XX:+HeapDumpOnOutOfMemoryError
> Notice groovy fails:
> Y
> Z
> java.lang.OutOfMemoryError: Java heap space
> Dumping heap to java_pid147612.hprof ...
> Heap dump file created [497819587 bytes in 0.136 secs]
> Caught: java.lang.OutOfMemoryError: Java heap space
> java.lang.OutOfMemoryError: Java heap space
> at test.TestOOM.test(TestOOM.groovy:31)
> at test.TestOOM.run(TestOOM.groovy:41)
> But Java version does not.
> It looks like all the values of s are still in memory (see screenshot), even though previous values should be discarded.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)