Giter Site home page Giter Site logo

Memory leak about go-gst HOT 7 CLOSED

onthegit avatar onthegit commented on May 17, 2024
Memory leak

from go-gst.

Comments (7)

RSWilli avatar RSWilli commented on May 17, 2024

Ah interesting, I was looking at the code for a while and wondered where something like this could occur.

The created C buffers are unrefed here and the wrapBuffer function you mention only performs a golang allocation.

The NewBufferFromBytes function seems to correctly unref all created C objects.

Ah but I see a lonely Ref() call in PushBuffer (aka no unref), that may be the source of your issue.

I even think that there shouldn't be a Ref() call in the first place, since gst_app_src_push_buffer takes ownership of the buffer.

@onthegit could you try it out and post your feedback, or provide me with a minimal setup that I can run and profile?

from go-gst.

RSWilli avatar RSWilli commented on May 17, 2024

@tinyzimmer what do you think?

from go-gst.

tinyzimmer avatar tinyzimmer commented on May 17, 2024

@tinyzimmer what do you think?

This isn't the first memory leak fought on those methods. The last one dates back to gstreamer 1.18.

I'll have to look more closely to see but last I recall that buffer is just populated with a memset from the original.

Debugging memory leaks in CGO is a particular pain. At the time a heavily tuned valgrind helped me track it down.

from go-gst.

onthegit avatar onthegit commented on May 17, 2024

Hello, thanks for your replies,
I tried replacing NewBufferFromBytes with

p.src.PushBuffer(gst.NewBufferFull(gst.MemoryFlagReadOnly, cp, int64(len(cp)), 0, int64(len(cp)), func() { fmt.Println("closed") }))

and the memory leak is even bigger. The function does print when the buffer is closed

from go-gst.

onthegit avatar onthegit commented on May 17, 2024

@RSWilli I tried removing Ref() and the memory still kept growing.

from go-gst.

onthegit avatar onthegit commented on May 17, 2024

It appears the there is memory leak in mp4mux element. Valgrind shows that there are a lot of allocations in gstreamer isomp4 library. The mp4mux element was set like this:

	if err = mux.SetProperty("faststart", true); err != nil {
		return nil, errors.New("could not set property: faststart " + err.Error())
	}

	if err = mux.SetProperty("fragment-duration", uint(60)); err != nil {
		return nil, errors.New("could not set property: fragment-duration " + err.Error())
	}

	mux.SetArg("fragment-mode", "first-moov-then-finalise")

Once they were removed, the leak was gone. I am still testing whether it will leak again but so far have not seen major increases in memory usage. Will test further.
So this might be a problem with the mp4mux element, and maybe someone with permissions at gstreamer repo can report the issue.

Worth mentioning is that there was no leak (from my short testing) when the pipeline elements (except src element) were replaced with fakesink

from go-gst.

RSWilli avatar RSWilli commented on May 17, 2024

You could talk to the gstreamer devs on the gstreamer IRC channel.

maybe someone with permissions at gstreamer repo can report the issue

You can create an account by yourself and get verified to report the issue, though.

from go-gst.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.