Reassign unique_ptr object with make_unique statements - Memory leak?

前端 未结 3 2142
深忆病人
深忆病人 2021-02-12 17:50

I don\'t get what following statement would do (specially second line)?

auto buff = std::make_unique(128);
buff = std::make_unique(512)         


        
3条回答
  •  醉酒成梦
    2021-02-12 17:57

    There is no memory leak here, the assignment will deallocate the resources associated with the first allocation. Not seeing it in the debugger most likely means the relevant call was just optimised out. Try compiling with -O0 if you want to see it.

提交回复
热议问题