1
std :: set 또는 std : vector와 같은 표준 템플릿 라이브러리 컨테이너를 사용하여 Microsoft Visual C++ (VS 2008/2010)에서 다음과 같이 메모리 누수가 발생합니다.C++ : std : main()에서 메모리 누수를 설정합니다.
#include <set>
#include <stdlib.h>
#include <crtdbg.h>
#define _CRTDBG_MAP_ALLOC
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
printf("I'm leaking\n");
std::set<int> s;
_CrtDumpMemoryLeaks();
return 0;
}
프로그램을 실행 한 후,이 같은 일부 출력을 얻을 것이다 : 그냥 같이 괄호로 정의를 묶 :
int _tmain(int argc, _TCHAR* argv[])
{
printf("I'm not leaking any more\n");
{
std::set<int> s;
}
_CrtDumpMemoryLeaks();
return 0;
}
다음
Detected memory leaks!
Dumping objects ->
{209} normal block at 0x005E9C68, 20 bytes long.
Data: <h^h^h^ > 68 9C 5E 00 68 9C 5E 00 68 9C 5E 00 CD CD CD CD
{208} normal block at 0x005E9C20, 8 bytes long.
Data: < ; > F8 FE 3B 00 00 00 00 00
Object dump complete.
이의 해결책
이상한 동작이며 이것이 Microsoft 컴파일러 또는 일부 STL- 문제인 버그입니까? 나는 그것이 이전의 것 같아요. Linux 시스템에서이 문제를 시도해 본 사람이 있다면 ...
예, 당신은 절대적으로 견고합니다! 그래서 전혀 버그 없음 :) – Knasterbax