id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	os	architecture	failure	difficulty	testcase	blockedby	blocking	related
2105	garbage collection confusing in ghci for foreign objects	Frederik		"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               
}}}
"	bug	closed	normal		GHCi	6.8.2	invalid			Unknown/Multiple	Unknown/Multiple	Runtime performance bug	Unknown				
