[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gstreamer-devel
Subject:    Re: Release RAM, when close or reload stream
From:       Aleksandr Slobodeniuk via gstreamer-devel <gstreamer-devel () lists ! freedesktop ! org
Date:       2024-04-17 15:51:00
Message-ID: CAHuwaLBZKM2qVdT5jDo0qHJRJ-ptnoUncBzzW3qx7E+mp3KU_A () mail ! gmail ! com
[Download RAW message or body]

Hi, this really sounds like a memory leak.
Quite likely that this will help:

1. set environment variables
GST_TRACERS="leaks(name=all-leaks)" GST_DEBUG=GST_TRACER:7
2. make sure that your application calls `gst_deinit()` before it
terminates.
3. run your app for a while (sounds like just opening 2 streams is enough),
and then close it (so everything gstreamer-related is supposed to be freed,
and the gst_deinit() is called afterwards).

If some of the objects (such as elements, buffers) remain alive (it means
there was a leak) at the moment of gst_deinit(), it will print a warning to
stderr, and will log each object in the gstreamer log (also stderr by
default).

If you have done all the steps and do not see any leak, it's quite useful
to add a leak on purpose to make sure the method works on your system. Like
just adding an extra ref on something.

If it still only shows the leak you add on purpose, consider building your
project with address sanitizer, this will catch all the leaks, not only in
the GStreamer-related objects.

Kind Regards,

Aleksandr Slobodeniuk

Senior Software Engineer

+34 936 03 42 35

Carrer de Jordi Girona, 29

08034, Barcelona, Spain.

<http://fluendo.com>

<https://es.linkedin.com/company/fluendo>   <https://twitter.com/fluendo>
<https://github.com/fluendo>


On Wed, Apr 17, 2024 at 4:15 PM Deymos s via gstreamer-devel <
gstreamer-devel@lists.freedesktop.org> wrote:

> I am developing a video wall for 32-64 streams, I faced the problem of
> increasing memory when restarting streams I have an example illustrating my
> problem.
> Example: https://github.com/Deymoss/Rtsp-player
> 
> When I start the application, a pipeline is created, as a result, the
> application initially takes 54MB of RAM, when I start the stream, the
> volume increases to ~ 110 MB, when I close the stream, the memory is not
> freed, when I run the same stream again, the amount of RAM increases to 120
> MB, and so on, 36 streams eats 5 gb RAM for 12 hours, the same is true for
> file files descriptors (I suspect BUS creates them)
> 
> How to properly clear the memory and all information about the stream when
> closing?
> 
> At the moment I'm setting the pipeline to NULL and not making an unref,
> but if I uncomment these lines:
> 
> gst_bus_set_sync_handler(m_videoPipe->bus, nullptr, nullptr, \
> nullptr);gst_object_unref(m_videoPipe->pipeline);gst_object_unref(m_videoPipe->bus);
>  
> nothing changes in memory consumption, although the refcount of each
> element and the pipeline itself at the end of the function is zero.
> 


[Attachment #3 (text/html)]

<div dir="ltr">Hi, this really sounds like a memory leak.<br>Quite likely that this \
will help:<br><br>1. set environment variables<br><span \
style="color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,&quot;Courier \
New&quot;,monospace;font-size:12px;font-variant-ligatures:none;background-color:rgba(29,28,29,0.04)">GST_TRACERS=&quot;leaks(name=all-leaks)&quot; \
GST_DEBUG=GST_TRACER:7</span><br>2. make sure that your application calls \
`gst_deinit()` before it terminates.<br>3. run your app for a while (sounds like just \
opening 2 streams is enough), and then close it (so everything gstreamer-related is \
supposed to be freed, and the gst_deinit() is called afterwards).<br><br>If some of \
the objects (such as elements, buffers) remain alive (it means there was a leak) at \
the moment of gst_deinit(), it will print a warning to stderr, and will log each \
object in the gstreamer log (also stderr by default).<br><br>If you have done all the \
steps and do not see any leak, it&#39;s quite useful to add a leak on purpose to make \
sure the method works on your system. Like just adding an extra ref on \
something.<br><br>If it still only shows the leak you add on purpose, consider \
building your project with address sanitizer, this will catch all the leaks, not only \
in the GStreamer-related objects.<br><br>Kind Regards,<br><br clear="all"><div><div \
dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div \
dir="ltr"><span><div dir="ltr" style="margin-left:0pt" align="left"><table \
style="border:none;border-collapse:collapse"><colgroup><col width="220"><col \
width="175"></colgroup><tbody><tr style="height:50.25pt"><td style="border-left:solid \
#ffffff 1pt;border-right:solid #ffffff 1pt;border-bottom:solid #f915ab \
1pt;border-top:solid #ffffff 1pt;vertical-align:top;padding:5pt 5pt 5pt \
5pt;overflow:hidden"><p dir="ltr" \
style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span \
style="font-size:10pt;font-family:&quot;DM \
Sans&quot;,sans-serif;color:rgb(0,0,0);background-color:transparent;font-weight:700;vertical-align:baseline">Aleksandr \
Slobodeniuk</span></p><p dir="ltr" \
style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span \
style="font-size:8pt;font-family:&quot;DM \
Sans&quot;,sans-serif;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline">Senior \
Software Engineer</span></p></td><td style="border-left:solid #ffffff \
1pt;border-right:solid #ffffff 1pt;border-bottom:solid #f915ab 1pt;border-top:solid \
#ffffff 1pt;vertical-align:top;padding:5pt 5pt 5pt 5pt;overflow:hidden"><p dir="ltr" \
style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span \
style="font-size:8pt;font-family:&quot;DM \
Sans&quot;,sans-serif;color:rgb(249,21,171);background-color:transparent;font-weight:700;vertical-align:baseline">+34 \
936 03 42 35</span></p><p dir="ltr" \
style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span \
style="font-size:8pt;font-family:&quot;DM \
Sans&quot;,sans-serif;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline">Carrer \
de Jordi Girona, 29</span></p><p dir="ltr" \
style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span \
style="font-size:8pt;font-family:&quot;DM \
Sans&quot;,sans-serif;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline">08034, \
Barcelona, Spain.</span></p></td></tr><tr style="height:0pt"><td \
style="border-left:solid #ffffff 1pt;border-right:solid #ffffff \
1pt;border-bottom:solid #ffffff 1pt;border-top:solid #f915ab \
1pt;vertical-align:top;padding:5pt 5pt 5pt 5pt;overflow:hidden"><br><p dir="ltr" \
style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><a href="http://fluendo.com" \
target="_blank"><span \
style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(17,85,204);background-color:transparent;vertical-align:baseline"><span \
style="border:none;display:inline-block;overflow:hidden;width:135px;height:23px"><img \
src="https://lh7-us.googleusercontent.com/7f4gLdr2vrB3tXPMwJmLsq1xFFFqPKnq7My8TnumcBKp \
IMI0HfrvUTStJeCYVUP7FynvoYZw1jq-6fQtHdK7u3qLC7NEmPMet6iQkYpoPcyp3EUYQBrOnhgFYa7XDzgeDkJjVBknQdmb76YE2o3c63s" \
width="135" height="23" \
style="margin-left:0px;margin-top:0px"></span></span></a></p></td><td \
style="border-left:solid #ffffff 1pt;border-right:solid #ffffff \
1pt;border-bottom:solid #ffffff 1pt;border-top:solid #f915ab \
1pt;vertical-align:top;padding:5pt 5pt 5pt 5pt;overflow:hidden"><br><p dir="ltr" \
style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><a \
href="https://es.linkedin.com/company/fluendo" target="_blank"><span \
style="font-size:10pt;font-family:&quot;DM \
Sans&quot;,sans-serif;color:rgb(17,85,204);background-color:transparent;font-weight:700;vertical-align:baseline"><span \
style="border:none;display:inline-block;overflow:hidden;width:23px;height:22px"><img \
src="https://lh7-us.googleusercontent.com/OzDx4NDORH8FwQh0Ux7Eqszty4oDNvLyo5ad22JS7q56 \
cErOlNi67GdfCqrm0usd5BLylF7NHaveLM3xgRy99wMKYbhF-BxnrlHeUpOzDHYrG0E70Yb78WFAZuuTG4XQAgSVBxhPIXz3WvcK2_PrW9I" \
width="23" height="22" style="margin-left:0px;margin-top:0px"></span></span></a><span \
style="font-size:10pt;font-family:&quot;DM \
Sans&quot;,sans-serif;color:rgb(51,113,242);background-color:transparent;font-weight:700;vertical-align:baseline"> \
</span><a href="https://twitter.com/fluendo" target="_blank"><span \
style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(17,85,204);background-color:transparent;vertical-align:baseline"><span \
style="border:none;display:inline-block;overflow:hidden;width:22px;height:22px"><img \
src="https://lh7-us.googleusercontent.com/dP_zElA4XMeIAQtvlavqqCuEG9zesjnBeqAMRtw-5HKz \
aLT5nyX49DGsOuwokHCOLVQZTvc1Ng7NPJ8ozUhweGF6BWx-33UYp5XEQSCAcefq4NfZOUGRQgRVWvv5Jyb725Rlc-zuXkM-T-MXCmqfVqo" \
width="22" height="22" style="margin-left:0px;margin-top:0px"></span></span></a><span \
style="font-size:10pt;font-family:&quot;DM \
Sans&quot;,sans-serif;color:rgb(51,113,242);background-color:transparent;font-weight:700;vertical-align:baseline"> \
</span><a href="https://github.com/fluendo" target="_blank"><span \
style="font-size:10pt;font-family:&quot;DM \
Sans&quot;,sans-serif;color:rgb(17,85,204);background-color:transparent;font-weight:700;vertical-align:baseline"><span \
style="border:none;display:inline-block;overflow:hidden;width:24px;height:23px"><img \
src="https://lh7-us.googleusercontent.com/xe27dLIuIPtsQqcHCI4EhUQzqxQmQTe3h0rsuabYwOv8 \
-BoHKM50vhxMKUsssJ91DmCTt_MsYCwxQmZq-8bIQY-9e3TFdbr3ckIfX3eSx1YKF5JB7LgH7v6qbjsn0ntflPyrb694cH-t9BYspEeZK-Q" \
width="24" height="23" style="margin-left:0px;margin-top:0px"></span></span></a><span \
style="font-size:10pt;font-family:&quot;DM \
Sans&quot;,sans-serif;color:rgb(51,113,242);background-color:transparent;font-weight:700;vertical-align:baseline"> \
</span></p></td></tr></tbody></table></div></span></div></div></div><br></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 17, 2024 at \
4:15 PM Deymos s via gstreamer-devel &lt;<a \
href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><p>I am \
developing a video wall for 32-64 streams, I faced the problem of increasing memory \
when restarting streams I have an example illustrating my problem.<br>
Example: <a href="https://github.com/Deymoss/Rtsp-player" rel="nofollow noreferrer" \
target="_blank">https://github.com/Deymoss/Rtsp-player</a></p> <p>When I start the \
application, a pipeline is created, as a result, the  application initially takes \
54MB of RAM, when I start the stream, the  volume increases to ~ 110 MB, when I close \
the stream, the memory is not  freed, when I run the same stream again, the amount of \
RAM increases to  120 MB, and so on, 36 streams eats 5 gb RAM for 12 hours, the same \
is true for file files descriptors (I  suspect BUS creates them)</p>
<p>How to properly clear the memory and all information about the stream when \
closing?</p> <p>At the moment I&#39;m setting the pipeline to NULL and not making an \
unref, but if I uncomment these lines:</p> \
<pre><code><span>gst_bus_set_sync_handler</span>(m_videoPipe-&gt;bus, \
<span>nullptr</span>, <span>nullptr</span>, <span>nullptr</span>); \
<span>gst_object_unref</span>(m_videoPipe-&gt;pipeline); \
<span>gst_object_unref</span>(m_videoPipe-&gt;bus); </code></pre>
<p>nothing changes in memory consumption, although the refcount of each 
element and the pipeline itself at the end of the function is zero.</p></div>
</blockquote></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic