OCaml Memory Management Best Practices
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
For operations like List.map, I would imagine that the what is actually occurring, is a new list of equal size is being constructed where an operation on the old map is happening for every element. I would like to know what the real implications are for the garbage collector, and how I can minimize the performance and memory impact. Things like List.append calculate a new list by constructing a copy. That's incredibly inefficient to me, both in the sense that each element afterward (time) needs to be copied, and in that more memory (space) is needed. In addition, is there a set of advice points that can be given to make sure that the garbage collector will appropriately see what it needs to in order to free items? In java, everything is reference counted, so if you want an object to be freed and you're maintaining it in a tree the lack of use of that object is better treated by going to the tree and updating the node that references it to mark it null. In this way, the garbage collector can collect the item that you were pointing to. OCaml is a different animal though, and it doesn't use reference counting. There doesn't seem to me to be any simple go-to practice in order to ensure that the GC will in fact collect an item that I know at the moment because it's operation is so different.