Harmonize GC handling #10
Labels
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
Source of really hard to track down bugs.
Currently, all three tree implementations manage their own memory. Being containers, they copy in whatever object is passed to them. If this has, say, a string, with a pointer to the GC heap it may be reaped when its original reference goes out of scope, even though the tree holds on to it. Potential disaster. Of course this can be avoided by passing only value types.
Because I first discovered this when dealing with IITree (indeed at that time I think the splaytree and avltree were using the GC to alloc anyway so it wasn't manifest there) I did implement in the IITree
insert
options(a) specify whether the passed in pointer (IITree takes a pointer instead of an object) was a GC managed pointer (
GCptr=true
), and(b) indicate whether it may contain other pointers to the GC heap (
trackGC=true
)See discussion here:
intervaltree/source/intervaltree/iitree.d
Lines 46 to 82 in 86578a3
Need to add
trackGC
option to the other tree implementations. Since they don't take pointer, probably skip addingGCptr
.Also TODO: document the difference in the APIs, and document that non-value-types shouldn't be added to splaytree and avltree for now.
The text was updated successfully, but these errors were encountered: