<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif;font-size:large"><br></div><br><div class="gmail_quote"><div dir="ltr">пн, 27 авг. 2018 г. в 19:46, Phyx <<a href="mailto:lonetiger@gmail.com">lonetiger@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>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.</div><div><br></div><div>The leak happens only when you do a foreign export because foreign exports create C wrappers to initializers for each function you export.</div><div><a href="https://github.com/ghc/ghc/blob/21f0f56164f50844c2150c62f950983b2376f8b6/compiler/deSugar/DsForeign.hs#L668" target="_blank">https://github.com/ghc/ghc/blob/21f0f56164f50844c2150c62f950983b2376f8b6/compiler/deSugar/DsForeign.hs#L668</a></div><div> <br></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>These are marked as static initializers, and as such the CRT will initialize them on
DLL_PROCESS_ATTACH
time. At DLL_PROCESS_DETACH</div><div>time the destructors would be run, but we don't have destructors for these initializers, so whatever they did will always persist.</div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:georgia,serif;font-size:large">Hello!</div><div class="gmail_default" style="font-family:georgia,serif;font-size:large">Thank you very much for such a detailed explanation! Now I gain an insight into what's happening.</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>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?<div class="gmail_default" style="font-family:georgia,serif;font-size:large;display:inline"></div></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:georgia,serif;font-size:large">Our goal was to understand whether we're cooking it in a wrong way or that's the implementation details of the Haskell RTS.</div><div class="gmail_default" style="font-family:georgia,serif;font-size:large">And your answer just suits our goal perfectly. Anyway I will submit a bug report as you suggested.</div></div><div class="gmail_default" style="font-family:georgia,serif;font-size:large"><br></div><div class="gmail_default" style="font-family:georgia,serif;font-size:large">Kind regards,</div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><i><div class="gmail_default" style="font-family:georgia,serif;font-size:large;display:inline">Olga Philippskaya</div>.</i><br></div></div></div>