aspose file tools
The moose likes Beginning Java and the fly likes primitives and garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "primitives and garbage collection" Watch "primitives and garbage collection" New topic
Author

primitives and garbage collection

anagha patankar
Ranch Hand

Joined: Dec 26, 2005
Posts: 53
as I understand primitives and object references are stored on the stack while the actual objects are stored on the garbage collectible heap .

Question being - so does this mean that the primitives on stack are never removed - are they ever garbage collected ?.

Regards,
-anagha
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24040
    
  13

That's right. Primitives on the stack are not garbage collected. But as soon as a method returns, the stack it used is eligible to be re-used -- the stack memory is simply overwritten. That's how a program stack works.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: primitives and garbage collection
 
Similar Threads
Stack and Heap
java compiler issues
What is a Heap Memory?
Threads
Stack n Heap