When do I need to free memory?

I learned C # and now I am learning C ++. The whole point of releasing memory is new to me, and I want to know when I need to worry about releasing memory, and when not.

From what I understand, the only case I have to worry about releasing memory is when I used the statement new, so I have to free the memory using delete.
But in these cases there is no need to release memory:

  • Class variables (members) or static variables.
  • Local variables in a function.
  • The STL family (string, list, vector, etc.).

It's true? And are there other times when I have to worry about freeing up memory?

+5
source share
2 answers

: new delete, new[] delete[] malloc free.

++ , ; ry , std::vector std::unique_ptr.

+9

, :

  • new/new[] i, delete/delete[]
  • malloc/calloc free

, . ++, malloc , , , , , , ., , , , : , C-based /API- , , .

, .

.. , , C ++, C, ++. p >

0

All Articles