Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

primitives and garbage collection  RSS feed

 
anagha patankar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!