std memory leak陷阱

  • 1632
  • 0

_CrtDumpMemoryLeaks() 偵測記憶體時會誤判的情形

在離開程式的時候呼叫
_CrtDumpMemoryLeaks();

檢查有沒有memory leak常常會因為

std::vector
std::string....

等標準函式庫的元件宣告成global造成記憶體檢查錯誤

 

解決方法就是使用指標new 出來在程式離開的時候delete這樣才不會造成_CrtDumpMemoryLeaks()
誤判...

我當初因為這樣debug超久...

 

還有只要是dotnet的東西gcnew出來也要記得delete但是c#卻沒這樣的困擾真是坑爹...