On Wed, 8 Feb 2023 at 10:06, Davide Perini <
perini...@dpsoftware.org> wrote:
> I noticed that if I start and stop the pipeline continuosly, every time
> I start it, my software sucks 20MB of RAM more.
> If I do it many times, the software sucks a lot of RAM.
>
> Is this "a memory leak" somewhere?
> Am I stopping the screen recording correctly? Should I set some object
> to null when I stop the pipeline?
Are you creating a pipeline each time? If so, and if you can, reuse
the existing pipeline.
This is kind of the expected behaviour. I assume the Pipeline
reference is overwritten or set to null? The problem is likely that
the native resources will not be released until the Java garbage
collector runs. And GStreamer native resources don't impact the Java
heap, so you can use up a lot of off-heap resources before the garbage
collector runs.
All native objects in the bindings can also be explicitly disposed.
One catch with that with Pipeline at the moment is that there might be
messages queued on the Bus that need to complete after calling stop().
You could look at doing (think this is correct - not at a dev machine) -
pipe.stop();
Gst.invokeLater(pipe::dispose);
This works in most cases by adding the disposal at the end of the
queue of bus messages. We should possibly change the behaviour of
dispose() on pipelines to do something like this automatically.
However there are some edge cases to consider.
I might have missed where the ScheduledExecutorService comes from in
your code. If it's not Gst.getExecutor() I would look at using that
instead - running things on that executor is recommended in most
cases.
Best wishes,
Neil
--
Neil C Smith
Codelerity Ltd.
www.codelerity.com
Codelerity Ltd. is a company registered in England and Wales
Registered company number : 12063669
Registered office address : Office 4 219 Kensington High Street,
Kensington, London, England, W8 6BD