c++ - Memory leak when using std::list -
how remove memory leak std::list
?
this example code :
#define _crtdbg_map_alloc #include <stdlib.h> #include <crtdbg.h> #include <iostream> #include <list> using namespace std; void main() { list<int> a; a.clear(); _crtdumpmemoryleaks(); }
when try run it, shows memory leak.
so, how remove it?
there no memory leak. report telling memory has not yet been deallocated, true. deallocated @ end of current scope - after _crtdumpmemoryleaks()
has run.
alter code follows; provide more accurate answer:
void main() { { list<int> a; a.clear(); } _crtdumpmemoryleaks(); }
note movement of a
container own scope.
Comments
Post a Comment