You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vart= collection.immutable.TreeMap.empty[Int, Int]
for (i <-1 to 100000)
t = (t + (i -> i) - i)
=== What is the expected behavior? ===
The loop should require constant memory, regardless of the number of iterations.
=== What do you see instead? ===
The memory footprint is increasing while the loop is running.
When it finishes, there are exactly 100001 TreeMap and RedBlack$$Empty$$ instances that cannot be garbage collected until the reference t goes out of scope.
If you run this loop for a larger number of iterations, you will get an OutOfMemoryError (out of JVM heap space).
=== Additional information ===
The problem goes away, when you always keep at least one element in the TreeMap. This code works correctly:
vart= collection.immutable.TreeMap(0->0) // never removedfor (i <-1 to 100000)
t = (t + (i -> i) - i)
@paulp said:
I believe this is fixed in r23767, but I'm not entirely sure that's not papering over the issue. If anyone feels the problem is inadequately addressed please reopen.
=== What steps will reproduce the problem? ===
=== What is the expected behavior? ===
The loop should require constant memory, regardless of the number of iterations.
=== What do you see instead? ===
The memory footprint is increasing while the loop is running.
When it finishes, there are exactly 100001
TreeMap
andRedBlack$$Empty$$
instances that cannot be garbage collected until the reference t goes out of scope.If you run this loop for a larger number of iterations, you will get an
OutOfMemoryError
(out of JVM heap space).=== Additional information ===
The problem goes away, when you always keep at least one element in the
TreeMap
. This code works correctly:JVisualVM suggests also that the problem might be related to the $$outer reference preventing 0-sized
TreeMap
objects from being GCed. (https://lampsvn.epfl.ch/trac/scala/ticket/1419)=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered: