Open scabug opened 16 years ago
Imported From: https://issues.scala-lang.org/browse/SI-743?orig=1 Reporter: cbordelo Attachments:
cbordelo said: i also attach the file
@dragos said:
You are right, there is indeed a problem. Let me first explain what happens: the big
field is 'in scope' inside object Helper
and as such, the most general case is handled by copying it into a field, when Helper
is created. When such objects are used only during initialization, they should not get a field, and here it seems we could do better with a more sophisticated analysis. It seems the case you commented out is handled, so as a temporary solution you could go that way.
It might help to make the dependency explicit, by having an init
method that takes the big object as parameter (and do so whenever big
is needed). That way, the compiler will not see big
as free, and won't generate these fields.
@dragos said: Well, I'm not so sure there is an easy fix for this issue...
@odersky said: It's indeed not so simple. We need to solve it, but can't do it right now.
Someone could look into whether the situation is any different or better in Scala 3.
By coincidence, I recently looked at it. Did the algorithm suggest this to you? Of all the gin joints etc.
IIRC S3 is no field, S2 is status quo. I haven't created a branch yet or assigned myself, as it seemed less like low-hanging and more like fruit on the ground, where it will not even bop anyone on the head like Newton's apple.
Hi folks,
I'm working with latest the Scala repository and observe a Java instance field i n the compiler generated output that I presume does not belong. Worse, at runtime via Java reflection I access the field and find its referencing a java/scala object that to my thinking should be available to GC. So, I view this as a compiler generated code caused memory leak. the version of scala is
and I'm using Java 6/Solaris 10 and/or Java 5/AIX for the test I also observed the same with 2.7.0GA where I first saw it. I include the code below and when run observe: ad.big$$1 is [I@e140e14
Note that if you change the code to comment out the (0 to 0).map ... line and use instead the new ... ArrayBuffer() ... line then the code up until the Console.println does the same thing, yet no big$$1 field is in A$$Helper$$2$$ and thus no memory issue and when run yields expected: Exception in thread "main" java.lang.NoSuchFieldException: big$$1
After the code listing is the javap -private output of the various .class files generated and one sees the A$$Helper$$2$$ having the big$$1 field
in my real world application "big" is a large intialization object constructed from parsing lots of data from a file and I want to see it getting GC'ed after its use in building the next stage object
Craig Bordelon bord@iscp.telcordia.com