Repeated hs_init()/hs_exit()

Simon Marlow simonmar at
Wed Jan 29 05:23:16 EST 2003

> Just out of curiosity, what would happen if hs_exit were a noop? if it
> left haskell initialized? I imagine there would be a space leak if you
> expected the rts's heap storage to be reclaimed, but is there any
> user-observable state which would cause programs to behave oddly? Just
> curious mainly, I don't advocate this as a solution.

hs_exit() has three main purposes in GHC:

 (1) it runs any remaining finalizers
 (2) it generates the stats output (eg. +RTS -sstderr)
 (3) it generates the profiling output

For (1), we're considering not running finalizers at all at exit time,
so that would cease to be a problem.  (2) and (3) aren't particularly
important - we'll probably do whatever is easiest for the time being,
which is to output the stats/profiling the first time and do nothing in
subsequent hs_exit()s.

An interesting question is whether we can return the RTS to its
completely uninitialised state, freeing all the dynamic memory it has
accumulated and so on.  There are two ways I can see to do this:

  - Reload the data pages of the executable/library from disk (on
    of course).

  - Arrange it so we can do the de-initialisation ourselves.  The main
    thing here is being able to revert all the CAFs that have been
    evaluated - we already have some of the machinery to do this.

I don't think we'll tackle this in the short term, but it would be a
nice feature to have.


More information about the FFI mailing list