[Haskell-cafe] Re: hs-plugins and memory leaks

Evan Laforge qdunkan at gmail.com
Wed Oct 20 21:37:06 EDT 2010

> Last, i remove pdynload code from my project temporary with below reasons:
> 1) Hold running state is difficult, like network state in browser or
> running state in terminal emulator.

This doesn't seem too hard to me.  Provided you are not swapping the
module that defines the state in the first place, simply reload the
module, and replace the old symbol in the state with the reloaded one.

> 2) Linking time is too long, I have haskell OS project
> (http://www.flickr.com/photos/48809572@N02/) have many sub-module, every
> sub-module is very big, and linking time is too long.

This is discouraging, since one of the main reasons to use dynamically
loaded code instead of recompiling the whole app is to avoid long link
times.  Presumably you would compile the majority of the app (the API
that the plugins use, and the internal code also uses) as a dynamic

main.o -> tiny stub that just calls app.so
app.so -> large library containing all app logic
plugin.so -> links against app.so when loaded

So the plugin needs to read a lot of hi files when recompiling, but
the dynamic link time should be proportional to the number of
unresolved symbols in plugin.so that point into app.so, not
proportional to the overall size of the app, right?

>> So would freeing oc->image fix the leak?  In my case, it's not too
>> hard to force all data structures that might reference it.
> It's not safe for GHC runtime system since you don't know when time
> unload old code is safe.

But that's just my question, I *do* (think I) know when it's safe,
which is after the data that has passed through plugged-in code has
been fully forced.  Can't I just call unloadObj then?

E.g., loading and unloading plugins for audio processing is totally
standard.  Since the data is strict arrays of primitive types, there's
no risk of stray pointers to unloaded code.

> Anyway, i was re-thinking hot-swap haskell some time, my idea
> is :
>     multi-processes framework
>   + hot-swapping core entry
>   + mix old/new sub-module in runtime
> Core and sub-module all in separate processes.

How would you pass state between processes?

More information about the Haskell-Cafe mailing list