Hi all, i am hunting a memory leak and suspsect it might be related to `refTo`. I am passing a ByteA...
u
Hi all, i am hunting a memory leak and suspsect it might be related to
refTo
. I am passing a ByteArray reference by calling bytes.refTo to POSIX
read
and now wonder when the pinning will be undone? I see that the
CValuesRef
returned by
getPointer
takes an
AutofreeScope
. Where does that come from? And when is it cleared? I.e. what is the lifetime of a
CValuesRef
returned by
refTo
?
d
The result of refTo is indefinitely valid, however when passed to a c interop function, the pointer seen by C is only valid during the function call.
u
thanks @Dominaezzz. that is the directly enclosing function call. as in:
Copy code
handleError(write(fd, buffer.refTo(0), 255))
the pointer could become invalid after `write`returns? and buffer can be garbage collected whenever it leaves it’s scope? So the pointer C sees is generated automagically by the compiler by calling
getPointer
when it sees a CValueRef being passed? And the compiler also creates the AutofreeScope enclosing the c-interop-call
d
That is correct.
So refTo won't cause a memory leak.
u
Cool. Thanks again. So now I only have to find my leak 🙂