<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
 --></style><title>Re: [Live-devel] How to delete live
objects</title></head><body>
<blockquote type="cite" cite>content-class:
urn:content-classes:message<br>
Content-Type: multipart/alternative;<br>
<x-tab>&nbsp;
</x-tab>boundary=&quot;----_=_NextPart_001_01C73803.925BB9BE&quot;<br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">Hi
All,</font><br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">In my code I
do the following:</font><br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">Groupsock*
sock = new Groupsock(Š);</font><br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">src = new
MultiframedRTPSource(Š);</font><br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">sink = new
MediaSink(Š);</font></blockquote>
<div><br></div>
<div>Presumably you really meant to say</div>
<div><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </x-tab>src =
SomeSubclassOfMultiFramedRTPSource::createNew(...);</div>
<div><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </x-tab>sink =
SomeSubclassOfMediaSink::createNew(...);</div>
<div><br></div>
<blockquote type="cite" cite><br></blockquote>
<blockquote type="cite" cite><font face="Arial"
size="-1">sink-&gt;startPlaying(*src, afterPlay, sink);</font><br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">void
afterPlay(void* user)</font><br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">{</font><br>
</blockquote>
<blockquote type="cite"
cite>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font face="Arial"
size="-1"> MediaSink* sink = (MediaSink*)user;</font><br>
</blockquote>
<blockquote type="cite"
cite>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font face="Arial"
size="-1"> Medium::close(src);</font><br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">delete
sock;</font><br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">}</font><br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">After the
program is finished I got memory leaks. If I try to delete sink
pointer it crashes.</font><br>
</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">What is the
right sequence of destruction here?</font></blockquote>
<div><br></div>
<div>Generally speaking, you should destroy objects in the opposite
order from that in which they were created.&nbsp; Also, subclasses of
&quot;Medium&quot; are destroyed using&nbsp;
&quot;Medium::close()&quot;, whereas &quot;Groupsock&quot; objects are
destroyed using &quot;delete&quot;.&nbsp; (This is historical
ugliness...)</div>
<div><br></div>
<div>Note, however, that if two or more source objects are chained
together using subclasses of &quot;FramedFilter&quot; - e.g., src1 --&gt;
filter2 --&gt; filter3 --&gt; sink4 - then you explicitly destroy only
&quot;sink4&quot; and &quot;filter3&quot;; &quot;filter2&quot; and
&quot;src1&quot; will get destroyed automatically when you destroy
&quot;filter3&quot;.</div>
<div><br></div>
<div>This doesn't apply in your case, so you should do:</div>
<div><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab>Medium::close(sink);</div>
<div><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab>Medium::close(src);</div>
<div><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </x-tab>delete
sock;</div>
<x-sigsep><pre>-- 
</pre></x-sigsep>
<div><br>
Ross Finlayson<br>
Live Networks, Inc.<br>
http://www.live555.com/</div>
</body>
</html>