[Haskell-cafe] ghci: Difference in garbage collection etc. between REPL and function

Brandon Allbery allbery.b at gmail.com
Thu May 9 14:50:38 CEST 2013


On Wed, May 8, 2013 at 9:54 PM, Niklas Hambüchen <mail at nh2.me> wrote:

> If I run these steps one by one in ghci, garbage ends up in my handle as
> expected.
>
> However, if I "let main = do ..." this whole block in order to pack it
> in a test case, it does not happen, neither in ghci nor ghc.
>

ghci is in many ways like an endless (or at least until ":l"/":r")
do-block. In particular, the handle remains in scope after you run your
commands at the prompt, so it is not garbage collected.  If you enclose it
into its own do block, this introduces local scope and the handle goes out
of scope and is garbage collected at the end.

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130509/59e861d4/attachment.htm>


More information about the Haskell-Cafe mailing list