posted 20 years ago
i'm just wondering....you know when you're 'finished' with an object you can set it to null to offer it up for garbage collection or whatever...
Not exactly. Objects can not be "set to null", but you can change references to objects to refer to null. Then, if no living reference refers to some object (as they've perhaps all been told to refer to null), that object would be available for garbage collection.
is there any such action that can be performed on primitive data types? i guess they don't take up too many resources in any case but just wondering all the same.
A primitive reference cannot be instructed to refer to null, as object references can. If a primitive reference exists, it always takes up the same amount of memory, no matter what value it holds.
primitive types are allocated on stack.. they die when the method returns.
Well, let's not forget about all those instance member variables and all those static member variables. They won't "die" until their associated object instance died, or in the case of static variables, until the class were unloaded from memory, which I believe only happens when the JVM terminates.