kamaci
kamaci

Reputation: 75237

Java variables that prone to be collected by garbage collector

I don't exactly remember but there was an article for Java that explains variable modifiers that makes them prone to be collected by garbage collector. Is there any mechanism for Java to define variables as stepped to be collecting by garbage collector?

Upvotes: 1

Views: 65

Answers (4)

Maurice Perry
Maurice Perry

Reputation: 32831

No, except for the weak reference api.

Upvotes: 0

Dhruv Gairola
Dhruv Gairola

Reputation: 9182

I think you were referring to the finalize keyword. Do take note that this only makes the suggestion to the compiler. The compiler may choose not to garbage collect. Or perhaps you were referring to weak references...

Upvotes: 0

Daniel
Daniel

Reputation: 3057

What you're looking for might be Weak Reference, have a look here: http://en.wikipedia.org/wiki/Weak_reference

Upvotes: 1

SJuan76
SJuan76

Reputation: 24895

If an object is referenced (directly or indirectly) by a variable, it won't be collected at all.

Apart from that, there is nothing. Garbage collector is a black box and just does what it fits (even System.gc() is only a suggestion to run the garbage collection).

Upvotes: 0

Related Questions