http://antrash.pixnet.net/blog/post/70456505-stack-vs-heap%EF%BC%9A%E5%9F%B7%E8%A1%8C%E6%99%82%E6%9C%9F%E5%84%B2%E5%AD%98%E5%85%A9%E5%A4%A7%E8%A6%81%E8%A7%92
Stack — A region of reserved memory in which programs store status data such as procedure and function call addresses, passed parameters,andsometimeslocalvariables.
Stack — A region of reserved memory in which programs store status data such as procedure and function call addresses, passed parameters,andsometimeslocalvariables.
Stack是儲存所有函式位置、函式引數和區域變數,由於這些資料在程式編譯的時
候已經決定,所以區域變數都會在函式結束或區段結束時解構。
Heap — A portion of memory reserved for a program to use for the temporary storage of data structures whose existence or size cannot be determined until the program is running. The program can request free memory from the heap to hold such elements, use it as necessary, and later free the memory.
Heap是儲存執行時期配置的資料,而且這段空間不會隨函式結束被解構,系統亦無法判斷儲存在Heap物件的生命週期,所以這些儲存在Heap物件生命週期的管理就是程式設計師的責任。