list will not release items for GC
emmanueltouzery opened this issue · 4 comments
such code:
// do a cheap slice by setting prefix length
bits = setPrefix(prefixSize - from, bits);
is not quite OK. list should wipe pointers to the items to enable them to be garbage collected, otherwise we have in effect a memory leak.. Items are unreachable for list users but list holds them in memory.
That is something I've been a bit unsure about. You're definitely right that it prevents garbage collection. But, you're right, it's not worth it to leak memory for a very small perf benefit.
not sure how it should be fixed within list
though. prune completely the nodes which become in effect unused in the tree (as in wipe subtrees entirely from the root down)? would that maybe break some other code which would expect these nodes to be present?
If there is an assumption the nodes are there, copying them all fill them with undefined
could have some cost. But I do think they must be freed because who knows what people could put in a list. Could be very large and expensive objects which really must be garbage collected.
This should be fixed by #74.
I don't understand your comment above @emmanueltouzery. Was that addressed by my comment here or are you thinking about something else?
yes your comment covered my question, it's all good, i'm closing this bug!