Discuss in detail the memory leak problem of C++

  • 2020-05-19 05:19:12
  • OfStack

1) have as much delete as you have new. And the paired new and delete should be in one function. If the data to be returned from a subfunction is created by new, my method is to create the corresponding data size at the location where the function needs to be called and pass it to the subfunction by pointer or reference.

2) I was quite careless. Once again, I put delete statement after return statement in the process of coding, resulting in the crash of 2 due to insufficient memory in the process of running the program. Check more than 20 times before check out, really crying mood have. I hope you take me as a warning, 1 must put the return statement at the end of the function, I guess I am the only one to make this boring mistake.


Related articles: