Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in interpreter #7366

Closed
scabug opened this issue Apr 13, 2013 · 4 comments
Closed

Memory leak in interpreter #7366

scabug opened this issue Apr 13, 2013 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Apr 13, 2013

When repeating many small interpretations the heap is full after a while.
Test Case:

$intp.interpret("var i = 0")
while (true) {$intp.interpret("""i = 1;println(i ":" + new java.util.Date)""")}

This provides the following output, showing that things first get faster and then slower and slower until the heap is full.
The fastest period of the execution (1046..1076) enables the creation of aorund 30 objects per second.
Then by 3000 it is getting really slow...

PS C:\Users\bjornr> scala
Welcome to Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_02).
Type in expressions to have them evaluated.
Type :help for more information.

scala> $intp.interpret("var i = 0")
i: Int = 0
scala> while (true) {$intp.interpret("""i = 1;println(i ":" + new java.util.Date)""")}
1:Sat Apr 13 15:29:25 CEST 2013
2:Sat Apr 13 15:29:26 CEST 2013
3:Sat Apr 13 15:29:26 CEST 2013
4:Sat Apr 13 15:29:26 CEST 2013
5:Sat Apr 13 15:29:26 CEST 2013
6:Sat Apr 13 15:29:26 CEST 2013
7:Sat Apr 13 15:29:26 CEST 2013
8:Sat Apr 13 15:29:27 CEST 2013
9:Sat Apr 13 15:29:27 CEST 2013
10:Sat Apr 13 15:29:27 CEST 2013
11:Sat Apr 13 15:29:27 CEST 2013
12:Sat Apr 13 15:29:27 CEST 2013
13:Sat Apr 13 15:29:27 CEST 2013
14:Sat Apr 13 15:29:27 CEST 2013
15:Sat Apr 13 15:29:27 CEST 2013
16:Sat Apr 13 15:29:27 CEST 2013
17:Sat Apr 13 15:29:28 CEST 2013
...
1045:Sat Apr 13 15:30:10 CEST 2013
1046:Sat Apr 13 15:30:11 CEST 2013
1047:Sat Apr 13 15:30:11 CEST 2013
1048:Sat Apr 13 15:30:11 CEST 2013
1049:Sat Apr 13 15:30:11 CEST 2013
1050:Sat Apr 13 15:30:11 CEST 2013
1051:Sat Apr 13 15:30:11 CEST 2013
1052:Sat Apr 13 15:30:11 CEST 2013
1053:Sat Apr 13 15:30:11 CEST 2013
1054:Sat Apr 13 15:30:11 CEST 2013
1055:Sat Apr 13 15:30:11 CEST 2013
1056:Sat Apr 13 15:30:11 CEST 2013
1057:Sat Apr 13 15:30:11 CEST 2013
1058:Sat Apr 13 15:30:11 CEST 2013
1059:Sat Apr 13 15:30:11 CEST 2013
1060:Sat Apr 13 15:30:11 CEST 2013
1061:Sat Apr 13 15:30:11 CEST 2013
1062:Sat Apr 13 15:30:11 CEST 2013
1063:Sat Apr 13 15:30:11 CEST 2013
1064:Sat Apr 13 15:30:11 CEST 2013
1065:Sat Apr 13 15:30:11 CEST 2013
1066:Sat Apr 13 15:30:11 CEST 2013
1067:Sat Apr 13 15:30:11 CEST 2013
1068:Sat Apr 13 15:30:11 CEST 2013
1069:Sat Apr 13 15:30:11 CEST 2013
1070:Sat Apr 13 15:30:11 CEST 2013
1071:Sat Apr 13 15:30:11 CEST 2013
1072:Sat Apr 13 15:30:11 CEST 2013
1073:Sat Apr 13 15:30:11 CEST 2013
1074:Sat Apr 13 15:30:11 CEST 2013
1075:Sat Apr 13 15:30:11 CEST 2013
1076:Sat Apr 13 15:30:12 CEST 2013
...
2867:Sat Apr 13 15:32:03 CEST 2013
2868:Sat Apr 13 15:32:04 CEST 2013
2869:Sat Apr 13 15:32:04 CEST 2013
2870:Sat Apr 13 15:32:04 CEST 2013
2871:Sat Apr 13 15:32:04 CEST 2013
2872:Sat Apr 13 15:32:04 CEST 2013
2873:Sat Apr 13 15:32:05 CEST 2013
...
3253:Sat Apr 13 15:37:34 CEST 2013
3254:Sat Apr 13 15:37:42 CEST 2013
3255:Sat Apr 13 15:37:50 CEST 2013
3256:Sat Apr 13 15:37:59 CEST 2013
3257:Sat Apr 13 15:38:09 CEST 2013
3258:Sat Apr 13 15:38:20 CEST 2013
3259:Sat Apr 13 15:38:33 CEST 2013
3260:Sat Apr 13 15:38:47 CEST 2013
3261:Sat Apr 13 15:39:08 CEST 2013
java.lang.OutOfMemoryError: Java heap space
at scala.collection.mutable.ListBuffer.$plus$eq(ListBuffer.scala:168)
at scala.collection.mutable.ListBuffer.$plus$eq(ListBuffer.scala:45)
at scala.collection.SeqLike$class.reverseMap(SeqLike.scala:279)
at scala.collection.AbstractSeq.reverseMap(Seq.scala:40)
at scala.tools.nsc.interpreter.Imports$class.reqsToUse$1(Imports.scala:137)
at scala.tools.nsc.interpreter.Imports$class.importsCode(Imports.scala:156)
at scala.tools.nsc.interpreter.IMain.importsCode(IMain.scala:77)
at scala.tools.nsc.interpreter.IMain$Request.(IMain.scala:841)
at scala.tools.nsc.interpreter.IMain.buildRequest(IMain.scala:447)
at scala.tools.nsc.interpreter.IMain.requestFromLine(IMain.scala:551)
at scala.tools.nsc.interpreter.IMain.requestFromLine(IMain.scala:545)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:598)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
at .(:11)
at .()
at .(:7)
at .()
at $print()
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:745)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:790)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:702)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:566)
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:573)

scala>

@scabug
Copy link
Author

scabug commented Apr 13, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7366?orig=1
Reporter: @bjornregnell
Affected Versions: 2.10.1
Duplicates #4331

@scabug
Copy link
Author

scabug commented Apr 13, 2013

@retronym said:
I'm marking this as a duplicate of #4331. The REPL retains certain data structure representing each line of code. You can flush these with reset(). But that doesn't work for leaks of the objects created by the interpreted code, which was the reported bug in #4331.

@scabug scabug closed this as completed Apr 13, 2013
@scabug
Copy link
Author

scabug commented Apr 13, 2013

@bjornregnell said:
The workaround mentioned in #4331 of doing reset kills all intermediate results so that's not helping in my situation, where a GUI is continuously feeding the interpreter with jobs to build the DSL structures incrementally. So I really need this fix...

@scabug
Copy link
Author

scabug commented Apr 13, 2013

@bjornregnell said:
Yes, this seems the same problem as in #4331; sorry for not spotting this duplicate.
At least here is a test case for testing the memory leak ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants