1

我用libavccodec爲Windowsavformat_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()。我找不到可以釋放記憶的組合。

回答

0

再回到這個萬一有人認爲這是有用的。

事實證明,如果我只是打開和關閉文件,有內存泄漏。但是,如果我執行(讀取,搜索等)函數,則不會發生內存泄漏。