c++ - gstreamer 内存泄漏

标签 c++ memory memory-leaks gstreamer

我有 gstreamer 的内存泄漏:

#include <iostream>
#include <string.h>
#include <glib.h>
#include <gst/gst.h>

using namespace std;

void info(const GstElement *const element)
{
        cout << "count: " << GST_OBJECT_REFCOUNT(element) << endl;
        cout << "disposing: " << GST_OBJECT_IS_DISPOSING(element) << endl;
}

int main()
{
    gst_init(NULL,NULL);
    GstElement *element = gst_pipeline_new("src");
    info(element);
    gst_object_unref(element);
    info(element);
    gst_deinit();
    return 0;
}

当我用 valgrind 控制我的代码时,我得到了这个结果:

==9098== Command: ./test_gstreamer
==9098== 
count: 1
disposing: 0
count: 0
disposing: 0
==9098== 
==9098== HEAP SUMMARY:
==9098==     in use at exit: 1,364,118 bytes in 2,199 blocks
==9098==   total heap usage: 21,877 allocs, 19,678 frees, 3,899,417 bytes allocated
==9098== 
==9098== LEAK SUMMARY:
==9098==    definitely lost: 60 bytes in 1 blocks
==9098==    indirectly lost: 240 bytes in 10 blocks
==9098==      possibly lost: 543,952 bytes in 880 blocks
==9098==    still reachable: 819,866 bytes in 1,308 blocks
==9098==         suppressed: 0 bytes in 0 blocks
==9098== Rerun with --leak-check=full to see details of leaked memory
==9098== 
==9098== For counts of detected and suppressed errors, rerun with: -v
==9098== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

为什么 gst_object_unref 没有释放所有内存? 为什么 GST_OBJECT_IS_DISPOSINGgst_object_unref 之后返回 false?

最佳答案

你能试试把你的 main 改成这样吗:

gst_init(NULL,NULL);
GstElement *element = gst_pipeline_new("src");
info(element);
gst_element_set_state (element, GST_STATE_NULL);
gst_object_unref(element);
info(element);
return 0;

认为这可能有效。

关于c++ - gstreamer 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10439407/

相关文章:

c++ - const 常量操作是否在运行时评估?

c++ - Lemon Parser 会跳过一些东西(或者我的误解)

c++ - c++ 多线程递归调用终止

ios - UIView动画增加内存

php - php 读取 1Gb 文件的内存限制应该是多少?

c++ - 这会导致内存泄漏吗?

c++ - 如何使用 C++ 从 Windows 注册表中获取 "Open With"程序及其完整路径?

c - 读取简单数据声明并响应分配给该变量的内存量的程序

java - 部署在 Wildfly 8.2.1 上的 Java 8 应用的 Metaspace 内存消耗问题

java - 代码中的内存泄漏问题