F # - Do I need to delete ref cells explicitly?

Are ref cells similar to pointers in the sense that they refer to data on the heap and need to be explicitly deleted? All the examples that I saw on the Internet do not have explicit delete calls.

+4
source share
2 answers

Are ref cells, like pointers, in the sense that they refer to data on the heap and need to be explicitly deleted?

No. F # runs on the CLR, which automatically manages memory through the garbage collector. Memory resources, even those that use the heap, do not need to be explicitly cleared by the developer, and in fact there is no mechanism by which you can explicitly delete a specific object.

Instead, the reference cell will have the right to garbage collection if it is no longer referenced. Sometime after that, it will automatically clear the GC.

This is true for most types that you generate in F #, as well as for records, discriminatory unions, classes, etc.

+3
source

How can you remove them explicitly?

, , , ref - , := ! getter/setter.

ref , , :

type Ref<'a> = { mutable value: 'a }
let (:=) (r: Ref<_>) v = r.value <- v
let (!) (r: Ref<_>) = r.value
+5

Source: https://habr.com/ru/post/1655476/


All Articles