[Haskell-cafe] hs-plugins and memory leaks

Evan Laforge qdunkan at gmail.com
Wed Oct 20 18:26:27 EDT 2010

>> So my questions are:
>> Why did lambdabot and yi abandon plugins?
> Because it was unmaintained for around 5 years, and was fundamentally
> less portable than simpler state serialization solutions that offered
> some of the same benefits as full code hot swapping.

Fair enough.  The idea of being able to make changes and see them
quickly enough for it to have an interactive feel is very appealing,
but maybe there are other ways to get there, such as improving link
time with dynamic linking (my current link time is around 24 seconds).
 State serialization + restart is definitely simpler and more robust.
But if it's impossible to get it fast enough otherwise, and there
aren't any other show stopping problems (I think even a known memory
leak may be dwarfed by the amount of data the app keeps in memory
anyway), then it might be worth it to me to maintain hs-plugins.

>> Is unloadObj a guaranteed memory leak?  As far as I can tell, it's
>> never called within ghc itself.  If the choices are between a memory
>> leak no matter how you use it and dangerous but correct if you use it
>> right, shouldn't we at least have the latter available as an option?
>> E.g. a reallyUnloadObj function that also frees the image.
> GHC never unloads object code, so yes, it will "leak" old code.

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.

>> Long shot, but are there any more principled ways to guarantee no
>> pointers to a chunk of code exist?  The only thing I can think of is
>> to have the state be totally strict and consist only of types from the
>> static core.  Would it be possible to hand responsibility for the
>> memory off to the garbage collector?
> It's really hard.

It happens in python for python bytecode, since it exists as a plain
data structure in the language.  E.g. 'code = compile('xyz')'.
Couldn't a haskell solution be along the same lines?  'code <- load
"X.o"; makeFunction code', and then makeFunction holds a ForeignPtr to
the actual code and there's some kind of primitive to call a chunk of
code as a function.

More information about the Haskell-Cafe mailing list