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

Doubt in stack

 
Dhivya rajagopal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi, i read that object references will store in stack memory. The Java system must know, while it is creating the program, the exact lifetime of all the items that are stored on the stack. i can't understand this. can you please explain it. what are the items will store in the stack?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a “beginning” question, so I shall move it.

Who told you objects live on the stack? That sounds mistaken. There are a few short-lived objects which are created on the stack (in Java6+ only), but other objects live on the heap. There are copies of their references on the stack as local variables, but that probably doesn’t answer your question.
As for finding the age of objects, it is worth googling for Java garbage collection.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic