I have a var
object in my class which can be very big due to its large content. To cope with the size issue, once in a while I have to create a new instance of this class, where the content is pruned. This is the reason that it's a "mutable".
A high-level view of my target class is this:
class FancyClass {
// this element gets big, but I keep pruning it.
var bigObject = initialize()
def soSth() {
bigObject.method1()
// once in a while I prune this
bigObject = bigObject.prune()
}
}
bigObject
is what gets big. Every few iterations, I replaced it with another object which is supposed to be smaller: bigObject = bigObject.prune()
.
The problem is that tracing the memory, the memory usage almost never shrinks. In fact, it consistently gets higher (instead of a little drop in the memory usage).
I suspect that after bigObject = bigObject.prune()
GC does not remove the old instance. Any thoughts on this issue?