[HOpenGL] Memory Leak
Shawn Garbett
shawn.p.garbett at vanderbilt.edu
Tue Jan 27 17:03:03 EST 2009
On Jan 27, 2009, at 1:07 PM, Shawn Garbett wrote:
> I'm pulling my hair out fixing a memory leak in an OpenGL program.
> Don't know if this is related to OpenGL, but I've not gotten any
> takers from IRC. I know the exact line of code that's causing it.
>
<snip>
I've gotten it down to this:
import Data.IORef
import Graphics.Rendering.OpenGL.GL.StateVar
-- THIS VERSION DOESN'T LEAK
--iter :: IORef Integer -> IO ()
--iter ref = do
-- i <- get ref
-- ref $=! ((i+1) `rem` 12)
-- iter ref
--
--main = do
-- ref <- newIORef (0::Integer)
-- iter ref
-- THIS VERSION DOESN'T LEAK
--data State = State { stuff :: IORef Integer }
--
--iter :: State -> IO ()
--iter state = do
-- i <- get $ stuff state
-- (stuff state) $=! ((i + 1) `rem` 12)
-- iter state
--
--main = do
-- ref <- newIORef (0::Integer)
-- iter State{stuff=ref}
-- LEAKS LIKE A SIEVE
data Leak = Leak {x :: Integer}
data State = State { stuff :: IORef Leak }
iter :: State -> IO ()
iter state = do
l <- get $ stuff state
(stuff state) $=! l{x=((x l) + 1 `rem` 12)}
iter state
main :: IO ()
main = do
l <- newIORef $ Leak{x=0}
let s = State{stuff = l}
iter s
> Shawn Garbett <shawn.p.garbett > at < vanderbilt.edu>
> Vanderbilt Cancer Biology
> 220 Pierce Ave, PRB 715AA
> Nashville, TN 37232
> Office: 615.936.1975
> Cell: 615.397.8737
More information about the HOpenGL
mailing list