Skip to content

Memory leak with reifyTypeable #54

@mniip

Description

@mniip

If a value is reified with reifyTypeable and then never reflected, its underlying StablePtr is leaked and never freed.

Example reproducer:

{- cabal:
build-depends: base, reflection
-}

import Control.Exception
import Data.Reflection

go :: Int -> IO ()
go 0 = pure ()
go n = reifyTypeable n $ \p -> do
  --evaluate (reflect p)
  go (n - 1)

main = go 10000000

Running this on my machine exhibits 160,031,904 bytes maximum residency (10 sample(s)). Uncommenting the evaluate reduces it to 35,984 bytes maximum residency (1 sample(s)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions