On Wed, May 8, 2013 at 9:54 PM, Niklas Hambüchen <mail@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@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net