This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hello all, I have very basic doubts.. what is the difference between stack and heap? isnt the stack a part of heap?? or it is somewhere else situated ?? and what are the things stored on heap and stack ( like local or instance variables or methods ) ??
There's no need to "clear" the stack. The stack contains parameters or local variables which are primitives or object references. When a method returns, the stack pointer just bumps back to where it was before the method call. Any parameters and local variables are now beyond the pointer.
When GC goes looking for references to objects it can't look in the stack beyond the pointer because it can't tell what that data is. A reference out there is not a reference any more, it's just some bits that might just as well be a few bits out of an int or double. Even if we could find a reference out there, it is now out of scope and doesn't factor into GC any more.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi