基本上,在我的程序中,我必须创建和销毁一个窗口。我总是使用相同的窗口指针来创建和销毁内容(纹理和渲染)。
我在此过程中发现内存泄漏,因此我编写了一个简单的程序来验证这一点,这里是代码。
该问题对Windows的影响更大,在测试结束时,在Ubuntu上,内存仅增加了约3MB(Windows上约为236MB)。
#include <iostream>
#include "SDL.h"
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* mainWindow;
SDL_Renderer* mainRenderer;
SDL_Texture* mainTexture;
for (int i = 0; i < 200; i++)
{
mainWindow = SDL_CreateWindow("Memory Leak Test v1.0", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, SDL_WINDOW_SHOWN);
mainRenderer = SDL_CreateRenderer(mainWindow, -1, SDL_RENDERER_ACCELERATED);
mainTexture = SDL_CreateTexture(mainRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, 320, 240);
if (i == 0)
{
std::cout << "SDL Memory Leak Tester, please check the amount of memory\noccupied by the process, then press Enter\n";
getchar();
}
SDL_Delay(50);
if (i == 199)
{
std::cout << "SDL Memory Leak Tester, please check the amount of memory\noccupied by the process, then press Enter\n";
getchar();
}
SDL_DestroyTexture(mainTexture);
SDL_DestroyRenderer(mainRenderer);
SDL_DestroyWindow(mainWindow);
}
std::cout << "Test finished, press Enter to close\n";
getchar();
return 0;
}
有什么主意吗?