
#15746: Memory leak in print when RTS option -N is >= 2 -------------------------------------+------------------------------------- Reporter: nmattia | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- In GHC 802 the code below runs with constant memory. In GHC 822, 843 and 861 the code below runs with constant memory only if at most one core is used. If the RTS option -N is set to anything greater than 1, the memory usage grows with the size of "big_file". {{{#!hs import Data.ByteString.Builder.Extra (defaultChunkSize) import Data.Function import System.IO import qualified Data.ByteString as BS main :: IO () main = do h <- openFile "big_file" ReadMode fix $ \loop -> do bs <- BS.hGetSome h defaultChunkSize if BS.null bs then pure () else do print bs loop }}} You can reproduce this by cloning https://github.com/nmattia/ghc-print- leak and running "nix-shell". Alternatively save the code above to "Main.hs" and run "ghc ./Main.hs -threaded -rtsopts" and then "./Main +RTS -M2M -N[1|2] > /dev/null". Side note: the memory does not grow as quickly if the _size_ of the bytestring is printed, i.e. it seems to be a problem specific to hPutStrLn/print as opposed to the actual file content/bytestring being retained. I first encountered this issue when using conduit for the loop. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15746 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler