
31 Oct
2013
31 Oct
'13
3:39 a.m.
* Edward Z. Yang:
Actually, this is precisely the problem. When is a GMP integer freed? It can have pointers to it from objects on the heap, so this free should only occur when the integer is dead, with no references from the heap. How can that be arranged? Well, the garbage collector is responsible for figuring this out. So why shouldn't they just live on the heap, and then smoothly integrate with the existing garbage collector.
The real problem here is that GHC uses the mpz_* functions and not the lower-level mpn_* functions, where the caller is responsible for memory management and which would play well with garbage collection (or any other memory management scheme).