I read lot of articles about garbage collection and almost all article tells about heap memory. so my question is "garbage collection collects stack memory or heap memory or both".
相关问题
- What uses more memory in c++? An 2 ints or 2 funct
- C# GC not freeing memory [duplicate]
- Achieving the equivalent of a variable-length (loc
- garbage collection best practices
- Too many Garbage collection threads
相关文章
- Threading in C# , value types and reference types
- Should client-server code be written in one “proje
- Algorithm for maximizing coverage of rectangular a
- Stack<> implementation in C#
- Is there an existing solution for these particular
- Java, Printing the stack values
- -fno-objc-arc not working to disable ARC
- How would a heap-allocated const object differ fro
You don't cite any particular technologies, but the use is fairly typical across languages.
The garbage collector only works on the managed heap. There may be multiple heaps in a single process, some of which are not garbage collected.
Variables allocated on the stack are deallocated when a method returns. The garbage colletor will use those variables to find live references, but it will not collect the memory.
At least in java, stack will be automatically de-allocated as you leave that stack frame, so there is no need to garbage collect.
I'm a java programmer so I don't have this problem, but in fact in C++, (I heard that) you will have to be careful with this because you can allocate objects on stack, and you can leave that stack frame, the object will be de-allocated and you can not use it anymore, etc.