• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusion in heap and stack - PLEASE HELP

 
gaurav pal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i read in K&B that all objects are created/stored on heap and local variables(including object references) are created/stored in stack. But I want to know that where are the instance variables, which are primitives are stored... ?
 
harilal ithikkat
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all the instance variables will be saved in the heap.
 
harilal ithikkat
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JAVARANCH Family
 
gaurav pal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you tell me that how a heap does memory management i.e. how does it store new variables and deletes old variables... ?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The Sun Certification Results forum, where you posted this, is not for asking questions like yours, but for posting your result when you passed a Sun certification exam. I will move your post to a more appropriate forum.
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gaurav pal wrote:can you tell me that how a heap does memory management i.e. how does it store new variables and deletes old variables... ?


Memory for Objects is allocated(on heap) when you create one using the "new" keyword. Freeing the memory is taken of by the garbage collector(which runs at its own discretion). Read up on garbage collection.

In Java, you dont have to worry about explicit memory allocation and de-allocation like you'd have to in C[malloc and free].
That said, you still have to take care that your code has no memory leaks and that it uses the memory efficiently.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic