I am curious if there is a way to delete and unallocate something in OCaml. For example, let us say I have an array initialized using:
let a = Array.make 10000 0;;
How do I "delete" a?
Thanks in advance.
I am curious if there is a way to delete and unallocate something in OCaml. For example, let us say I have an array initialized using:
let a = Array.make 10000 0;;
How do I "delete" a?
Thanks in advance.
The short answer is that values are deleted (by the garbage collector) when they can no longer be accessed.
If this definition of a is a global definition, it is always accessible. Hence it will never be deleted.
If, instead, this is a local definition in a function it will be deleted when the function returns (or possibly sooner if the last reference is before the end of the function).
In general, immutable global values won't ever be garbage collected. If you want this, you can use a mutable global value:
let a = ref (Array.make 10000 0)
When you no longer need a you can do this:
a := [| |]