
Isn't it this simple: the Static Pointer Table must be a source of roots for the garbage collector. Of course! An item in the SPT may be looked up at any time. Easy. What am I missing? I'm deeply suspicious of any solution that involves a call to performGC. That smells wrong. Simon | -----Original Message----- | From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of | Facundo DomÃnguez | Sent: 18 November 2014 00:44 | To: ghc-devs@haskell.org | Subject: Fwd: Garbage collection | | Hello, | While working in the StaticPointers language extension [1], we | found we have some unusual CAFs which can be accessed after some | periods of time where there is no reference to them. | | For instance, the following program when compiled contains no | reference to `g`. `g` is actually looked up at runtime in symbol | tables via the call to `deRefStaticPtr`. | | g :: String | g = "hello" | | main = | deRefStaticPtr (static g) >>= putStrLn | | Desugars to: | | g :: String | g = "hello" | | main = | deRefStaticPtr (StaticPtr (StaticName "" "Main" "g")) >>= putStrLn | | In principle, there is nothing stopping the garbage collector from | reclaiming the closure of `g` before it is dynamically looked up. | | We are considering using StablePtrs to preserve `g`. So the code | desugars instead to: | | g :: String | g = "hello" | | main = | deRefStaticPtr (let x = StaticPtr (StaticName "" "Main" "g") | in unsafePerformIO $ newStablePtr g >> return | x | ) >>= putStrLn | | This solution could be temporal though, until we implement the so | called static pointer table, which would keep the values alive. | | Would you have any comments about such a solution or maybe would you | advice some other alternative? | | Thanks, | Facundo | | [1] https://ghc.haskell.org/trac/ghc/wiki/StaticPointers | _______________________________________________ | ghc-devs mailing list | ghc-devs@haskell.org | http://www.haskell.org/mailman/listinfo/ghc-devs