본문 바로가기

도구의발견

Visual Studio 2010에서 std::vector<std::string>::insert 메모리 릭

inserting in a std::vector of std::string causes memory leak

 

위와 같은 보고가 있었군요. 요약을 하자면 아래 코드를 실행 하면 메모리 릭이 발생한다는 것.

#include "stdafx.h"

#include <string>
#include <vector>

int _tmain(int argc, _TCHAR* argv[])
{
    // debug memory leaks
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

    {
         std::vector<std::string> vec;
         vec.reserve(3);
         vec.push_back("1");
         vec.insert(vec.begin(), 2, "2");
     }
 
     return 0;
}

 

VS 2010 SP1에서 패치 되었다고 하니 어서 어서 패치해야 할 듯..

유익한 글이었다면 공감(❤) 버튼 꾹!! 추가 문의 사항은 댓글로!!