garbage collection confusing in ghci for foreign objects
Hello, I am not sure if this is a bug or just a question. I have a linear algebra library which is allocating vectors etc. on the heap, I think mostly with newForeignPtr. When I use my library in ghci, and turn on debugging, it becomes clear that vectors I create are being garbage collected about one second after they are created:
> let v = ...
> v
(prints debugging info as v is computed)
(prints representation of v)
> (one second later, prints a debugging message
indicating that v has been freed)
Thus, the fact that ghci still has a symbol called 'v' is not enough to keep its data from being GC'ed, it seems. Is this a feature? If I create a string from the same data, then the string is not GC'ed:
> let v = ...
> let vstr = show v
> vstr
(prints debugging info as v is computed)
(prints quoted representation of v)
> (one second later, prints debug message
indicating that v has been freed)
> vstr
(prints quoted representation of v as above,
but no computation / no debugging messages,
indicating that 'vstr' data was not GC'ed)
I can provide more background if necessary. In my library, the primary datatypes interfacing to foreign blocks are:
-- Allocated blocks
-- uses 'newForeignPtr finalizerFree'
type RAlloc e i = (ForeignPtr CChar, ForeignPtr e)
-- "Raw Sparse Vector"
data RSV e i = RSV (ForeignPtr (RSV e i)) (RAlloc e i)
deriving Typeable
Trac metadata
Trac field | Value |
---|---|
Version | 6.8.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | GHCi |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Unknown |
Architecture | Unknown |