Haskell DLL (using FFI) causes memory leak.

Ольга Филиппская olga.kenobi at gmail.com
Tue Aug 28 11:35:10 UTC 2018


пн, 27 авг. 2018 г. в 19:46, Phyx <lonetiger at gmail.com>:

> Hi,
>
> You're likely just hitting a memory leak, Haskell DLLs and the RTS aren't
> designed to be unload-able, which is why you can't call hs_init again after
> you stop.
>
> The leak happens only when you do a foreign export because foreign exports
> create C wrappers to initializers for each function you export.
>
> https://github.com/ghc/ghc/blob/21f0f56164f50844c2150c62f950983b2376f8b6/compiler/deSugar/DsForeign.hs#L668
>
>
These are marked as static initializers, and as such the CRT will
> initialize them on DLL_PROCESS_ATTACH time. At DLL_PROCESS_DETACH
> time the destructors would be run, but we don't have destructors for these
> initializers, so whatever they did will always persist.
>

Hello!
Thank you very much for such a detailed explanation! Now I gain an insight
into what's happening.



>
> Your use case is fairly uncommon, but file a bug report against the leaks
> anyway. Why do you need to keep loading and unloading the dll?
>

Our goal was to understand whether we're cooking it in a wrong way or
that's the implementation details of the Haskell RTS.
And your answer just suits our goal perfectly. Anyway I will submit a bug
report as you suggested.

Kind regards,
-- 
*Olga Philippskaya.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20180828/3a21fe69/attachment.html>


More information about the ghc-devs mailing list