SDL2 是否存在内存泄漏? [英] Has SDL2 a memory leak?

查看:43
本文介绍了SDL2 是否存在内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到我所有使用 SDL2 的项目都有内存泄漏,所以我写了一个看起来像这样的小测试程序:

I noticed that all of my projects that use SDL2 have memory leaks, so I have written a little test program that looks like this:

SDL_Init(SDL_INIT_VIDEO);
SDL_Window *win = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 100, 100, SDL_WINDOW_RESIZABLE);
SDL_Renderer *ren = SDL_CreateRenderer(win, 0, 0);

bool running = true;
SDL_Event event;
while (running) {
    while(SDL_PollEvent(&event) != 0) {
        if(event.type == SDL_QUIT) {
            running = false;
        }
    }

    SDL_RenderClear(ren);
    SDL_RenderPresent(ren); //Thanks to keltar 
}
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();

我没有注意到任何可能导致泄漏的地方.

I haven't noticed anything that could produce a leak here.

我正在使用来自 Xcode 的 Instruments 来检测泄漏.前十秒没有泄漏.在接下来的 10 秒内,大约产生了 15 次泄漏.在程序启动后 40 秒内,这将继续不那么强烈.从 40 秒开始,没有产生新的泄漏,但分配的内存仍在不断增长.当我使用 SDL_RenderPresent 时,内存不再增长.

I'm using Instruments, from Xcode, to detect the leaks. The first ten seconds there are no leaks. In the next ten seconds about 15 leaks are created. This will continue less intense up to 40 seconds after the program has started. From 40 seconds on no new leaks are created, but the allocated memory still grows constantly. The memory no longer grows, when I use SDL_RenderPresent.

那么 SDL2 是否存在内存泄漏,是我在代码中犯了错误还是 Instruments 制造了一些误报?

So has SDL2 a memory leak, did I make a mistake in the code or is Instruments creating some false positives?

推荐答案

可能是因为您没有删除某个对象,或者您在循环中重新创建它而犯了一些错误.SDL2 本身不应该有任何内存泄漏.但是,我强烈建议您使用最新版本(目前是 2.0.10).请尝试在您的演示程序中绘制一些内容以验证这里没有任何内存泄漏.尝试重复项目代码的一小部分以呈现相似的效果.此代码没有任何意义,也无法重现您的问题.但是,如果您发现此处是 SDL2 端的真正内存泄漏,请在此处提交报告 https://bugzilla.libsdl.org/.在此之前,请从官方 Mercurial 存储库 https://hg.libsdl.org/SDL/ 并重试您的测试以确认该错误仍然存​​在于主流中.

It's possible some mistake where you didn't remove a certain object, or you are re-creating it in a loop. SDL2 itself shouldn't have any memory leaks. However, I highly recommend you to use the freshest version (2.0.10 on this moment is). Please try to draw something in your demo program to verify here is no any memory leaks. Try to repeat a small part of your project's code to render similar. This code doesn't anything and can't reproduce your issue. However, if you have found here is a real memory leak on SDL2 side, please submit a report here https://bugzilla.libsdl.org/. Before that, please pull most fresh sources from official Mercurial repository https://hg.libsdl.org/SDL/ and retry your test to confirm that bug is still presented in the mainstream.

这篇关于SDL2 是否存在内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆