Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null

 
W Martin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...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.
Thanks
Will
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
primitive types are allocated on stack.. they die when the method returns.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
W Martin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, thanks for clearing that up
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic