C # heap and stack on personal understanding

First, the interpretation of the stack (Stack) is allocated during compilation good memory heap (Heap) is dynamically allocated memory during program run Second, the difference between the stack usually keeps step we execute the code: as AddFive () method, int pValue variables on the heap is mostly stored objects, data and so on. Stack not have their own management, not owned by GC management, when the top element after use, automatically released by the GC heap management, is in memory of the clean-up value of the GC stack type of data storage; reference heap types of data stored in the memory, and when the memory unit store only objects in a heap memory allocation and destroyed as a class instance of the object created, the different members of the object by category was assigned to the different memory areas, a value type and reference type of pointer is assigned to the stack, a reference type of the object instance is assigned to the managed heap, static members is assigned to the global data area. The pointer on the stack will point to the object on the heap. When finished using the object, contact references and actual objects will be disconnected, thus causing the object hibernation. Because the stack self-maintenance, its memory management can be done through the operating system, at a time of hibernation heap objects need to be recovered by using a certain algorithm garbage collector (GC), release the memory occupied by the object.

Guess you like

Origin www.cnblogs.com/xuzy-x/p/11707445.html