[Live-devel] How to delete live objects

Ross Finlayson finlayson at live555.com
Sun Jan 14 10:52:05 PST 2007


>content-class: urn:content-classes:message
>Content-Type: multipart/alternative;
>	boundary="----_=_NextPart_001_01C73803.925BB9BE"
>
>Hi All,
>
>In my code I do the following:
>
>Groupsock* sock = new Groupsock(Š);
>
>src = new MultiframedRTPSource(Š);
>
>sink = new MediaSink(Š);

Presumably you really meant to say
	src = SomeSubclassOfMultiFramedRTPSource::createNew(...);
	sink = SomeSubclassOfMediaSink::createNew(...);

>
>sink->startPlaying(*src, afterPlay, sink);
>
>void afterPlay(void* user)
>
>{
>
>         MediaSink* sink = (MediaSink*)user;
>
>         Medium::close(src);
>
>delete sock;
>
>}
>
>After the program is finished I got memory 
>leaks. If I try to delete sink pointer it 
>crashes.
>
>What is the right sequence of destruction here?

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...)

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".

This doesn't apply in your case, so you should do:
	Medium::close(sink);
	Medium::close(src);
	delete sock;
-- 

Ross Finlayson
Live Networks, Inc.
http://www.live555.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.live555.com/pipermail/live-devel/attachments/20070114/015a6b27/attachment.html 


More information about the live-devel mailing list