How to free memory in try-catch blocks?

后端 未结 9 2122
时光说笑
时光说笑 2021-01-31 18:33

I have a simple question hopefully - how does one free memory which was allocated in the try block when the exception occurs? Consider the following code:

try
 {         


        
9条回答
  •  清酒与你
    2021-01-31 18:57

    I have to agree with all those that said RAII, however, I'd use Boost's shared_array instead of an auto_ptr. Auto pointer calls delete and not 'delete []' which will cause leaks with an array.

提交回复
热议问题