withStorableArray making IORefs
Simon Marlow
simonmar@microsoft.com
Tue, 13 Aug 2002 10:34:32 +0100
> I'm guessing it's not safe to use "newIORef" as the function=20
> argument to
> withStorableArray, but in a simple case [1], it seems to work okay. I
> suppose the danger is if the RTS decides to move the array. Does this
> happen IRL?
The danger is rather that the array might get freed. A StorableArray
contains a ForeignPtr to the array, and the finalizer on the ForeignPtr
will free the array after the last use. If you obtain a pointer to the
array by nefarious means (ie. 'withStorableArray return' would do it)
then the RTS might free the array while you still have a pointer to it.
Cheers,
Simon