Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# - Do ref cells need to be deleted explicitly?

Are ref cells like pointers in the sense that they reference data on the heap, and need to be explicitly deleted? All the examples I've seen online don't have explicit delete calls.

like image 503
user3685285 Avatar asked Feb 07 '23 02:02

user3685285


1 Answers

How would you delete them explicitly?

Also if you take a look at the source code you'll see that ref cell type is just an immutable wrapper over a mutable field, and the := and ! operators are simply getter/setter calls.

You can implement ref in a similar way yourself quite easily:

type Ref<'a> = { mutable value: 'a }
let (:=) (r: Ref<_>) v = r.value <- v
let (!) (r: Ref<_>) = r.value
like image 95
Honza Brestan Avatar answered Feb 11 '23 15:02

Honza Brestan