1
我用libavccodec爲Windows和avformat_open_input()
似乎有顯著內存泄漏。如果我打開了5,000個視頻,則操作系統會報告消耗的2 GB RAM,該應用程序退出時不會釋放該RAM。代碼如下:Windows版libavcodec中的內存泄漏?
AVFormatContext *pFormatCtx = NULL;
AVDictionary *dict = NULL;
int result = 0;
av_register_all();
// open the input video file
IntPtr ip = Marshal::StringToHGlobalAnsi(videoFilename);
const char* filename = static_cast<const char*>(ip.ToPointer());
result = avformat_open_input(&pFormatCtx, filename, NULL, &dict);
if (result < 0) {
Marshal::FreeHGlobal(ip);
return result;
}
Marshal::FreeHGlobal(ip);
avformat_close_input(&pFormatCtx);
return result;
上述代碼位於從C#調用的類庫中。我正在使用託管C++來調用libavcodec庫。流程是C# - > Managed C++ - > libavcodec。我使用DLL和動態鏈接。這是一個單線程應用程序。如我所料,當我使用線程時,泄漏會增加。
我已經試過如下:
- 我試過一對夫婦32位的構建和內存泄漏是一致的。
- 使用
NULL
,而不是&dict
。 - 調用
avformat_open_input()
與相同文件名5,000+次其中不是泄漏內存。 - 使用組合
avformat_alloc_context()
和avformat_free_context()
。我找不到可以釋放記憶的組合。