> I know I can request that the JVM run GC overall, but can
> this be done on a particular object?
No. Because of the way garbage collection works, the virtual machine
would need to basically traverse the entire object graph anyway just to
determine if that object is referenced from any other live objects. If
that's the case, then you may as well free up all the other dead objects
at the same time. To do otherwise would be like spending all day
cooking a seven course meal, then eating a biscuit and throwing the
remainder in the trash.

Signature
Chris Smith
Wojtek Bok wrote On 10/30/06 12:17,:
> Is it possible to run garbage collection on a particular instance of a class?
>
[quoted text clipped - 5 lines]
>
> I know I can request that the JVM run GC overall, but can this be done on a particular object?
Probably not. It would amount to having the program assert
"such-and-such object is garbage," an assertion the JVM would
need to verify before it could be acted upon. (Consider the
consequences of collecting an object that did in fact have a
few live references still kicking around, whether through error
or through malice.)
To verify that an object is truly garbage (or that it is not
non-garbage, which may be a better description of contemporary
collectors), the JVM would need to do pretty much the same
amount of work it would do for an ordinary GC. It seems to me
that "trustworthy selective GC" would not offer much savings
over ordinary GC; TSGC would just complicate the JVM and might
even make ordinary GC slower by imposing extra bookkeeping.

Signature
Eric.Sosman@sun.com
Wojtek Bok - 30 Oct 2006 19:48 GMT
> Wojtek Bok wrote On 10/30/06 12:17,:
>> Is it possible to run garbage collection on a particular instance of a class?
>
> Probably not.
That is what I thought.
Another problem would be how to do the call, as any usual method needs a reference to the object, yet that is the object we want to GC.
So I guess user one (this is a web app) consumes the memory and user two gets to wait while the GC runs :-))
Thanks!
Chris Smith - 31 Oct 2006 16:52 GMT
> To verify that an object is truly garbage (or that it is not
> non-garbage, which may be a better description of contemporary
[quoted text clipped - 3 lines]
> over ordinary GC; TSGC would just complicate the JVM and might
> even make ordinary GC slower by imposing extra bookkeeping.
I suppose an exception would be that if the collector were generational,
the call could be interpreted as "collect up to and including the
generation that contains this object".

Signature
Chris Smith