What is a memory leak?

前端 未结 8 2165
无人共我
无人共我 2020-11-27 05:50

Obviously Wikipedia has a fair amount of information on the topic, but I wanted to make sure I understand. And from what I can tell it\'s important to understand the stack/h

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 06:25

    Your function variables are also on the stack usually, not the heap. In most systems, the heap is used for dynamic allocations. The usual memory leak situation is

    1. Call some function F
    2. F allocates (new or malloc) some memory
    3. F returns to caller (no delete/free)
    4. pointer pointing to the dynamically allocated memory is out of scope
      • the memory is still allocated.
      • You can't delete/free it anymore

提交回复
热议问题