In Cost of weak pointers and finalizers at the GHC , writes Edward Yang (emphasis added):
A weak pointer can also be associated with a finalizer that starts when an object collects garbage. Haskell finalizers are not guaranteed.
I can’t find any documentation supporting this claim. The docs System.Mem.Weakare not explicitly about this. What I need to know is some entity that has the identity ( MutVar#, MutableArray#, Array#etc.) If I am attached to it finalizer if he will be safely called when the value gets GCed?
The reason is because I plan to do something like this:
data OffHeapTree = OffHeapTree
{ ref :: IORef ()
, nodeCount :: Int
, nodeArray :: Ptr Node
}
data Node = Node
{ childrenArray :: Ptr Node
, childrenCount :: Int
, value :: Int
}
, ( , ), OffHeapTree . . , mkWeakIORef ?