[Issue 12915] RedBlackTree leaks memory

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jun 13 12:41:18 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12915

safety0ff.bugz <safety0ff.bugz at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |safety0ff.bugz at gmail.com

--- Comment #2 from safety0ff.bugz <safety0ff.bugz at gmail.com> ---
RedBlackTree does not guarantee that remove operations won't invalidate
iterators, this guarantee is only present for inserts. So I think this is
acceptable.

As you've stated, we must use _left, _right and  _parent to null out the
pointers.

(In reply to Steven Schveighoffer from comment #1)
> Can we just null the end node's pointers on the destructor? this should
> dereference all the nodes.

This can be done in addition to Martin's solution, just call clear().
I'm not sure this will have a big impact:

The RedBlackTree's nodes form a cycle, a false pointer into any node will still
cause the entire tree to be retained.

And since the begin & end pointers are always on the heap, as the number of
nodes in the tree increases the likely hood of the begin & end being the ones
causing the leak diminishes.

If this is a pervasive issue, perhaps a function which recursively nulls the
pointers is in order (and optionally manually deallocates.)
Nulling would invalidate iterators, manually deallocating invalidates
references.

--


More information about the Digitalmars-d-bugs mailing list