좋아, 화면에서이를 업데이트하고 반영 할 수있는 정수를 표시하려고했습니다. (e.x. 마우스 위치의 x와 y 좌표를 보여줌), 나는 원했던대로 실행했지만, 좋은 ol'task 관리자를 열었고 7 분 동안 실행 한 후 약 600MB에 도달했다. 화면에 렌더링 한 정수를 주석 처리했을 때 (그리지 않거나 업데이트하지 않도록) 이 프로그램은 7 분 후에 약 20MB의 용량을 나타 냈습니다. 나는 문제를 찾는데 실패했다. 누군가 내가 잘못 갔는지 알아낼 수 있을까? 감사.SDL_TTF 메모리 누수 문자열을 그리는 중입니까?
TextManager.cpp
void textManager::intToString(Uint32 number, int x, int y)
{
ss << number;
text = ss.str().c_str();
surface = TTF_RenderText_Blended(font, text.c_str(), color);
if (surface == NULL)
cout << "surface is NULL \n" << SDL_GetError() << "\n";
texture = SDL_CreateTextureFromSurface(Gfx::Instance()->getRenderer(), surface);
SDL_FreeSurface(surface);
src.x = 0;
src.y = 0;
src.w = dst.w = surface->w;
src.h = dst.h = surface->h;
dst.x = x;
dst.y = y;
SDL_QueryTexture(texture, NULL, NULL, &src.w, &src.h);
ss.str(std::string().c_str());
}
void textManager::draw()
{
SDL_RenderCopy(Gfx::Instance()->getRenderer(), texture, &src, &dst);
}
textManager::~textManager()
{
if (texture != NULL)
SDL_DestroyTexture(texture);
font = NULL;
surface = NULL;
ss.clear();
delete surface;
}