funkia / list

🐆 An immutable list with unmatched performance and a comprehensive functional API.
MIT License
1.65k stars 51 forks source link

list will not release items for GC #72

Closed emmanueltouzery closed 5 years ago

emmanueltouzery commented 6 years ago

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.

paldepind commented 5 years ago

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.

emmanueltouzery commented 5 years ago

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.

paldepind commented 5 years ago

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?

emmanueltouzery commented 5 years ago

yes your comment covered my question, it's all good, i'm closing this bug!