[Live-devel] small leaks?
Ross Finlayson
finlayson at live.com
Fri Jul 16 09:35:11 PDT 2004
Returning to an old thread:
>>>*media.cpp, _Tables* getOurTables(UsageEnvironment& env)
>>>l 49:
>>> env.liveMediaPriv = new _Tables;
>>>
>>>But nowhere I see deletion of liveMediaPriv.
>>
>>Yes, this is a 'leak', albeit an unimportant one, because programs that
>>use these libraries will typically create very few "UsageEnvironment"
>>objects (in fact, usually just one), and the lifetime of these objects
>>will typically be the same as that of the entire program.
>>Unfortunately, there's no good way to fix this without making the
>>"UsageEnvironment" class aware of the "liveMedia" library - something
>>that I don't want to do, because I want to allow for programs that use
>>the "UsageEnvironment" library without the "liveMedia" library. But as I
>>noted above, this is not an important 'leak'.
>
>I understand.
>An alternative way to cure this would be to delete liveMediaPriv in
>BasicUsageEnvironment instead of in UsageEnvironment:
>
>BasicUsageEnvironment::~BasicUsageEnvironment() {
> if (liveMediaPriv != NULL){
> delete (_Tables*)liveMediaPriv;
> liveMediaPriv = NULL;
> }
>}
No, this has the same problem as before: It requires that
"BasicUsageEnvironment" be aware of the "liveMedia" library.
But it also has a more serious problem: It would be deleting the object
(media) tables without ensuring that the tables were empty - i.e., that the
tables no longer held objects that were still being used.
This has all been fixed in the latest version of the code. Now, the
"liveMediaPriv" and "groupsockPriv" structures are reclaimed (and these
fields reset to NULL) if and only if the corresponding tables are
empty. (In particular, for media objects, this means that they must all
have been closed using "Medium::close()".)
Also, the destructor for "UsageEnvironment" is no longer public. Instead,
"UsageEnvironment" objects are now reclaimed using the public "reclaim()"
member function. (This function doesn't actually delete the
"UsageEnvironment" unless both the "liveMediaPriv" and "groupsockPriv"
fields are NULL.)
However, if your code reclaims all objects, and then calls
"UsageEnvironment::reclaim()", then all allocated memory will be freed.
Ross Finlayson
LIVE.COM
<http://www.live.com/>
More information about the live-devel
mailing list