Weak pointers to static objects are sometimes not detected as unreachable
(See also the mailing list thread)
Static objects with no SRTs and pointer fields are currently ignored by evacuate(). This is efficient but causes trouble when checking alive-ness of static objects in isAlive(), which is used for (among other things) checking whether a weak's key has died. This causes leaks as value of a weak with static key will always be kept alive.
Here's a demonstration:
module Main where
import System.Mem.Weak (mkWeak, deRefWeak)
import System.Mem (performMajorGC)
mkKey :: IO String
mkKey = readFile "/dev/random"
-- mkKey :: IO Int
-- mkKey = return 1
main :: IO ()
main = do
w <- mkKey >>= \k -> mkWeak k () Nothing
performMajorGC
performMajorGC
performMajorGC
deRefWeak w >>= print
The idea is that the first mkKey function returns a non-static string and this program prints Nothing. If I enable the second mkKey function the key is now a static object and the program prints Just ().
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.5 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Runtime System |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |