aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Pool and Heap's of Confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Pool and Heap Watch "Pool and Heap New topic
Author

Pool and Heap's of Confusion

Yogesh Mhatre
Greenhorn

Joined: Feb 15, 2001
Posts: 20
I have been refering to this site from last 2/3 days and came across the following terminology hard to digest can anyone pls explain me what does "String pool" and "Heap" actually mean
Fawad Khan
Ranch Hand

Joined: Feb 13, 2001
Posts: 36
Hi Yogesh,
"Heap" is a virtual area of memory where the original value of the object created is stored while the referrence of that is stored in the "Stack" memory area.
"Pool of String" refers to the area in memory where the the String ( which is stored as an array ) is kept and that does not allow two strings with the same value, rather that creates 2 referrence of that same string value. And this resides in the "Heap" memory area.

Seeking Certification
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Objects are created on the heap. Garbage collection is done to keep the heap clean.
Variables are created in the stack. Each method has it's own stack. If it is a local variable, when the method completes, the stack for that method is discarded. The garbage collector does not do this. The variable will be discarded whenever the variable goes out of scope.
However the String literal "XYZ" will get created at class load time in the Constant Pool, the garbage collector will not get rid of that. String Literals are NOT objects. The Constant Pool is a separate area of memory from the heap and the stack.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Yogesh Mhatre
Greenhorn

Joined: Feb 15, 2001
Posts: 20
hi Cindy
when u say tht----
"for a local variable, when the method completes, the stack for that method is discarded. The garbage collector does not do this. The variable will be discarded whenever the variable goes out of scope.-------
do you mean tht the local variables like the String literals on the String pool are never garbage collected
Yogesh
[This message has been edited by yogesh mhatre (edited February 21, 2001).]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Local variables are disposed of, but not by the garbage collector . Well, technically there is nothing preventing a vendor from creating a JVM that uses the garbage collector to clean up stacks, it would just be very inefficient. When the system is done with the stack for the method, the entire stack gets zapped by the system instead of the garbage collector utility.
The constant pool is not garbage collected. But constants are tiny compared to objects so it is no big deal.
nan sh
Ranch Hand

Joined: Jan 05, 2001
Posts: 167
Hi Cindy,
If as you said that string literals created in constant pool
, if I have an application which deal with a lot of string literals(said,50k of string literals), I have to use StringBuffer, otherwise memory will dry out, is it right?


Have you tried this Mock Exam Testing Engine yet?<br /><a href="http://www.mycgiserver.com/~nan111/index.html" target="_blank" rel="nofollow">www.mycgiserver.com/~nan111/index.html</a>
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
No, most implementations of the JVM put the constant pool in ROM (Read only memory = very efficient, that's why java uses String Literals instead of String objects as often as it can) so it does not compete in any way for the RAM that the Heap and the stack use.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pool and Heap's of Confusion