多线程视频解码器泄漏内存 [英] Multi-Threaded Video Decoder Leaks Memory

查看:160
本文介绍了多线程视频解码器泄漏内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意图是创建一个相对简单的视频播放系统,以在我正在开发的较大程序中使用.与视频解码器相关的代码是此处.到目前为止,我能做的最好的就是将内存泄漏的范围缩小到本节代码(或者更确切地说,我没有注意到不使用视频时发生的任何内存泄漏).

这可能是一个非常广泛的问题,我如何不确定所遇到的问题的范围以及如何表达我的问题.

我想知道的是我错过了什么或做错了什么,导致了明显的内存泄漏(值得注意的是,我的意思是我可以看到每分钟内存使用率上升兆字节).我已尝试确保我进行的每个分配都与一个解除分配匹配.

编辑1
这将在运行MSYS2(MinGW64)的Windows 10计算机上构建

解决方案

捕获泄漏的最佳方法是在编译器上的内置内存泄漏检查器中使用,如果可以编译的话,它比valgrind更好.

将此行添加到您的makefile中:

CXXFLAGS += -fno-omit-frame-pointer -fsanitize=address -ggdb3 -O0

如果您使用旧版gcc(不支持内存清理程序/检查器,请使用clang).

如果不满足某些条件,我知道的av_packet_unref可能无法按预期方式工作(您可以在ffmpeg源代码中阅读更多内容,不记得它是头文件之一在谈论这些的名称). /p>

编译后,让内存明显上升,然后使用 Ctrl + C 退出.内存清理程序将自动转储已分配内存(以后不释放)的函数/行.如果看不到源代码行号,请使用addr2line工具.

希望有帮助.

My intention is to create a relatively simple video playback system to be used in a larger program that I am working on. Relevant code to the video decoder is here. The best I have been able to do so far is narrow down the memory leak to this section of code (or rather I have not noticed any memory leaks occurring when video is not used).

This is probably a very broad question how ever I am unsure of the scope of the issue I am having and as such of how to word my question.

What I want to know is what have I missed or done wrong that has lead to a noticeable memory leak (by noticeable I mean I can watch memory usage climb megabytes per minute). I have tried ensured that every allocation that I make is matched by a deallocation.

EDIT 1
This is to be built on a Windows 10 machine running MSYS2 (MinGW64)

解决方案

Best way to catch a leak is to use in built memory leak checker on compiler, way better than valgrind if you can compile with it.

Add this line to your makefile:

CXXFLAGS += -fno-omit-frame-pointer -fsanitize=address -ggdb3 -O0

If you use old version of gcc (which doesn't support memory sanitizer/checker use clang).

What I know is av_packet_unref may not work as expected if certain conditions not met (you can read more on inside ffmpeg source codes, can't remember the name it was one of the header files talks about these).

After compilation, let memory climb noticeable, then use Ctrl+C to quit. Memory sanitizer will dump the function/line where memory allocated (and not freed later) automatically. If you can't see source code line numbers, use addr2line tool.

Hope that helps.

这篇关于多线程视频解码器泄漏内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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