gpt4 book ai didi

c++ - gstreamer 内存泄漏

转载 作者:太空狗 更新时间:2023-10-29 21:48:34 24 4
gpt4 key购买 nike

我有 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: 1disposing: 0count: 0disposing: 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com