memory leak
This simple test program leaks memory for no obvious reason.
module Main where
import Control.Monad
import Control.Monad.Trans.Reader
main :: IO ()
main = do
runReaderT task ()
main
task :: ReaderT () IO ()
task = forM_ [(1::Integer)..] $ \cnt -> do
return cnt
However, there are some minor changes that (each individual change alone) make this program run in constant memory.
- If I remove
module Main where
- If I remove recursive call to main
- If I put task definition under the scope of main, like so
module Main where
import Control.Monad
import Control.Monad.Trans.Reader
main :: IO ()
main = do
runReaderT task ()
main
where
task :: ReaderT () IO ()
task = forM_ [(1::Integer)..] $ \cnt -> do
return cnt
Any of the changes above make the program run OK, but I belive that this should be also true for the original test program. I am not sure where the problem is (if at all), but it's extremely difficult to isolate this kind of problem in the real application.
Please check if anything can be done on the compiler or runtime to prevent this kind of problems.
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |