ghci unload

Simon Marlow
Thu, 9 May 2002 10:14:09 +0100

>     I was wondering if anyone had any suggestions/advice on the=20
> following... I am doing dynamic loading using bits of GHCi and it
> all works very nicely.
>     occasionally however I want to unload a module and reload=20
> it... this=20
> works fine however I remember from some other post that
> the memory from the unload is not reclaimed. This would=20
> explain the slow=20
> memory creap I am seeing.
>     So, finally, here's my question: why is it difficault to recover=20
> this memory - is there any way of doing it - remembering that I am
> not actually using anything from GHCi apart from the linker =20

The problem, in a nutshell, is that it is difficult to guarantee that
there are no references from the heap to objects or info tables in the
code object we want to unload.  This amounts to providing a hard
guarantee that there are no space leaks in your program - we can try
hard to make sure we don't have a space leak, but actually *promising*
this isn't practical.

We considered having the garbage collector flag an error if it found a
reference to unloaded code, but decided against it because it would be
impossible in general to prevent these kind of bugs.

Do you have some measurements on how much memory is being lost over
time?  I also know of several other ways that GHCi leaks memory during
use, so it might not just be the object files.