clearing GHCi (and, by extension, hint) loaded module dependencies

Simon Marlow marlowsd at gmail.com
Tue Sep 21 05:35:15 EDT 2010


On 18/09/2010 03:03, Alex Suraci wrote:
> Context: My language uses hint to interpret Haskell code at runtime,
> via `load: "path/to/file.hs"`. Hint works similar to ":load foo.hs"
> in GHCi (it uses the GHC API). After the source is interpreted the
> module's `load` function is executed in the language's VM. There is
> no valuable result; it is executed for its side-effects, usually
> definitions.
>
> Problem: Around 80MB[1] is used up by the module's dependencies and
> never freed. Subsequent "load:"s are faster, but that 80MB overhead
> can be expensive on things like VPSes.
>
> This can be simulated in GHCi by doing ":load foo.hs" followed by a
> ":load" to clear the loaded modules; the memory usage doesn't go down
> (understandably, in this case), and :loading it again is much
> faster.
>
> Is there any way to "hard reset" or free the memory being used for
> the loaded module's dependencies?

The memory is held on to by the GHC Session, so if you discard the 
Session and start a new one all the cached information should be released.

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list