Last active
May 26, 2020 19:50
-
-
Save pepeiborra/06ea0c5e4b4982bb1b0e0a9263f12634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setValues state key file val = do | |
currentValue <- HMap.lookup (file, Key key) <$> readVar state | |
_ <- evaluate currentValue | |
let fin = Just (hPutStrLn stderr "AN OLD VALUE GOT RELEASED") | |
weak <- (evaluate >=> \v -> mkWeakPtr v fin) `traverse` currentValue | |
modifyVar_ state $ \vals -> do | |
-- Force to make sure the old HashMap is not retained | |
evaluate $ HMap.insert (file, Key key) (fmap toDyn val) vals | |
whenJust weak $ \w -> do | |
performGC | |
b <- deRefWeak w | |
if isNothing b then hPutStrLn stderr "GONE AFTER INSERT" else do | |
hPutStrLn stderr "DEREF VALUE STILL LIVES AFTER INSERT" | |
updatedMap <- readVar state | |
_ <- evaluate updatedMap | |
performGC | |
b <- deRefWeak w | |
if (isNothing b) then hPutStrLn stderr "GONE AFTER EVALUATING THE MAP" else do | |
hPutStrLn stderr "DEREF VALUE STILL LIVES AFTER EVALUATING THE MAP" | |
_ <- evaluate $ HMap.lookup (file, Key key) updatedMap | |
performGC | |
b <- deRefWeak w | |
if isNothing b then hPutStrLn stderr "GONE AFTER LOOKUP" else do | |
hPutStrLn stderr "DEREF VALUE STILL LIVES AFTER LOOKUP" | |
_ <- evaluate $ length $ show updatedMap | |
performGC | |
b <- deRefWeak w | |
if (isJust b) | |
then hPutStrLn stderr "DEREF VALUE STILL LIVES AFTER FORCING THE MAP" | |
else hPutStrLn stderr "GONE AFTER FORCING THE MAP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: