<!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>
</x-tab>boundary="----_=_NextPart_001_01C73803.925BB9BE"<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> </x-tab>src =
SomeSubclassOfMultiFramedRTPSource::createNew(...);</div>
<div><x-tab> </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->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> <font face="Arial"
size="-1"> MediaSink* sink = (MediaSink*)user;</font><br>
</blockquote>
<blockquote type="cite"
cite> <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. Also, subclasses of
"Medium" are destroyed using
"Medium::close()", whereas "Groupsock" objects are
destroyed using "delete". (This is historical
ugliness...)</div>
<div><br></div>
<div>Note, however, that if two or more source objects are chained
together using subclasses of "FramedFilter" - e.g., src1 -->
filter2 --> filter3 --> sink4 - then you explicitly destroy only
"sink4" and "filter3"; "filter2" and
"src1" will get destroyed automatically when you destroy
"filter3".</div>
<div><br></div>
<div>This doesn't apply in your case, so you should do:</div>
<div><x-tab>
</x-tab>Medium::close(sink);</div>
<div><x-tab>
</x-tab>Medium::close(src);</div>
<div><x-tab> </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>