[GHC] #7936: newStdGen leaks memory when result is not used

GHC cvs-ghc at haskell.org
Sun May 26 22:38:19 CEST 2013


#7936: newStdGen leaks memory when result is not used
-----------------------------+----------------------------------------------
Reporter:  ryantrinkle       |          Owner:                  
    Type:  bug               |         Status:  new             
Priority:  normal            |      Component:  libraries/random
 Version:  7.6.3             |       Keywords:                  
      Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
 Failure:  Runtime crash     |      Blockedby:                  
Blocking:                    |        Related:                  
-----------------------------+----------------------------------------------
 When newStdGen is invoked repeatedly without making any use of the
 resulting StdGen values, it leaks memory, as in the following:

 {{{
 -- Leaks memory
 main = forever newStdGen
 }}}

 When a random number produced by the result is evaluated, no leak occurs:

 {{{
 -- Does not leak memory
 main = forever $ do
   r <- newStdGen
   evaluate $ fst $ next r
 }}}

 However, evaluating the result itself is not sufficient to eliminate the
 leak:

 {{{
 -- Leaks memory
 main = forever $ do
   r <- newStdGen
   evaluate r
 }}}

 After sufficient iterations of newStdGen, subsequent use will cause a
 stack overflow:

 {{{
 -- Causes stack overflow
 main = do
   replicateM 1000000 newStdGen
   r <- newStdGen
   evaluate $ fst $ next r
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7936>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the ghc-tickets mailing list