|
[GHC] #698: allocaBytes does not actually free the memory after the computa: msg#00048lang.haskell.glasgow.bugs
#698: allocaBytes does not actually free the memory after the computation -------------------------------+-------------------------------------------- Reporter: guest | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (FFI) | Version: 6.4.1 Severity: normal | Keywords: Os: Linux | Difficulty: Unknown Architecture: x86 | -------------------------------+-------------------------------------------- allocaBytes does not appear to free the memory after the computation has completed. For example, start ghci and run: {{{allocaBytes (100*1024*1024) $ \_ -> getLine}}} ghci's virtual memory usage will jump up by 100MB. When you press enter however, it does not drop back down. restart ghci and try: {{{bracket (mallocBytes 100*1024*1024) free $ \_ -> getLine}}} This time when you press enter, the memory usage will drop back down to its pre mallocBytes usage. This also happens for compiled programs. Note: the above test will only alloc virtual memory since nothing is ever read into the malloc'd memory. The following test program will actually force the pages to be mapped. It results in the same broken behaviour with the addition that the resident size of ghci gets stuck high. {{{ module Main where import Control.Exception import Foreign.Marshal.Alloc import Foreign.Ptr import Data.Word import System.IO import System.Mem test :: Int -> IO () test mb = let size = mb * 1024 * 1024 in do -- bracket (mallocBytes size) free $ wait size -- this version works allocaBytes size $ wait size -- this version does not free the memory afterwards performGC wait :: Int -> Ptr Word8 -> IO () wait size p = bracket (openBinaryFile "/dev/scsi/host0/bus0/target0/lun0/part1" ReadMode) (hClose) (\h -> hGetBuf h p size >> putStrLn "waiting..." >> getLine >> return ()) main = do test 150 putStrLn "is it free?" getLine return () }}} -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/698> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler_______________________________________________ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@xxxxxxxxxxx http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [GHC] #697: Bad assembler generated, GHC |
|---|---|
| Next by Date: | [GHC] #699: GHCi doesn't implement foreign import on amd64 when interpreting., GHC |
| Previous by Thread: | [GHC] #697: Bad assembler generated, GHC |
| Next by Thread: | Re: [GHC] #698: GHC's internal memory allocator never releases memory back to the OS, GHC |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |