[matroska-devel] Re: Memory leaks in libmatroska partially fixed

Steve Lhomme steve.lhomme at free.fr
Tue Feb 25 16:26:09 CET 2003


En réponse à Ronald Bultje <rbultje at ronald.bitfreak.net>:

> 
> Hey Steve & co,
> 
> On Tue, 2003-02-25 at 15:52, Steve Lhomme wrote:
> > No that's correct. The allocated memory is not freed because, as I
> said in the
> > previous email, the chidren on "head" are not freed when "head" is
> (which is an
> > EbmlMaster). I'll add something to automatically free these EbmlMaster
> children.
> > 
> > I will use a locking system so that if you really want to keep an
> element in
> > memory, you can (and you become the father will all responsabilites
> ;).
> 
> Shouldn't you just use refcounting here?
> 
> (short explanation:) Each user of an object ref()s it (incease
> refcount
> with one), and if you're done using it you unref() (decrease refcount
> with one) it. The one that created the object (ref() is an implicit
> part
> of object creation) should use unref() too. If noone uses the object,
> the refcount is zero (since everyone unref()ed it) and the object is
> automagically free()ed (in unref(), a check is done to see whether
> refcount is zero - if so, you delete the object).

Something like a garbage collector ?
That could work if we trapped all allocation and check for unfreed but
referenced element at the end. I'm not sure it would prevent more bugs. If
someone forget to ref/unref an element for example. While locking seems more formal.
http://www.matroska.org



More information about the Matroska-devel mailing list