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
Garbage collecting REPL bindings... #4331
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4331?orig=1 |
@paulp said: |
@retronym said: byte[33554432] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...}
a of $line6.$read$$iw$$iw$
MODULE$ of $line6.$read$$iw$$iw$
[15] of java.lang.Object[40]
elementData of java.util.Vector
classes of scala.tools.nsc.interpreter.IMain$TranslatingClassLoader
classLoader of scala.reflect.runtime.Mirror |
@paulp said: |
@SethTisue said: |
@retronym said (edited on Nov 11, 2015 4:36:38 AM UTC): Fixing that perhaps doesn't go far enough to provide a useful answer for the enhancement request, however. From my commit comment:
|
@som-snytt said: The PR for ScriptEngine uses Dynamic selection in the template; maybe there's a convenient syntax for doing that from a REPL session. Alternatively, more general switching of templates would allow the kinds of wrappings described (vars or softrefs or other holders, etc). There is or was a mechanism for wrapping every computation, IIRC. |
@SethTisue Hi, is there any solution for this issue? The memory leak is a big problem in our situation. |
I don't know of any solution or workaround. I wonder, though, if anyone has investigated whether the situation is any different under |
Retronym's reset workaround saga is at scala/scala#5657
but since 2.12.4
The class loader fix was forward-ported, but it looks like the repl refactor is broken (with or without
|
@SethTisue Hi, -Yrepl-class-based does not make any different. |
@som-snytt If the variable b was assigned two times by new Array[Byte](256 * 1024* 1024), why not gc the first object: new Array[Byte](256 * 1024* 1024) to free memory? |
@runzhiwang Indeed. But it could be captured by a subsequent definition Currently, the old value is a member of a statically reachable object, so there is no ordinary mechanism to make it collectable. The quicker fix suggested by the OP would be for the REPL to wrap values in SoftRefs and also accesses in a dereferencing get. If a value has been collected, the REPL could recompute it. |
= problem =
A lot of values that I compute are huge, and when done in the REPL, a
binding similar to:
val res3 =
is introduced by Scala. After a few of these bindings I run out of memory, and
have to start the REPL afresh.
Workarounds like always binding a var at the REPL and clearing it, or wrapping all REPL values with SoftReference are too annoying.
= analysis =
= enhancement recommendation =
Always bind top level values to some fixed identifier like "it", etc.
The text was updated successfully, but these errors were encountered: