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_DISPOSING
之后gst_object_unref
会返回false?
答案 0 :(得分:1)
您可以尝试将主要内容更改为:
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;
认为这可行。
答案 1 :(得分:1)
你应该做valgrind建议的事情:“重新运行--leak-check = full以查看泄漏记忆的详细信息”。请在此处查看答案:http://gstreamer-devel.966125.n4.nabble.com/Valgrind-error-with-gstreamer-td4657149.html
当gst_object_unref返回时,元素完成处理。