When a function ends are its local variables deallocated?

前端 未结 4 1374
日久生厌
日久生厌 2021-01-02 05:20

If not does that mean that I would have to end each function by deleting all local variables if I wanted to prevent 100% of memory leak?

4条回答
  •  暖寄归人
    2021-01-02 05:31

    The local variables that are allocated on stack, i.e. without using memory allocation functions or operators like malloc and new, are deleted automatically. All other variables have to be deleted by using delete as they are stored on heap.

提交回复
热议问题