如何停止需要增加内存量的Gloss?

时间:2012-11-20 17:52:48

标签: haskell graphics

我正在使用光泽来创建Haskell中的RTS游戏,但我注意到即使是非常简单的程序也会在运行时占用越来越多的内存。例如,以下程序将逐渐增加其内存使用量(每秒需要~0.025mb)。

module Main (
    main
)
where

import Graphics.Gloss
import Graphics.Gloss.Interface.IO.Game

main = 
    playIO (InWindow "glossmem" (500, 500) (0,0)) white 10 0
    (\world -> return (translate (-250) 0 (text $ show world)))
    (\event -> (\world -> return world))
    (\timePassed -> (\world -> return $ world + timePassed))

我已经尝试在运行时限制堆大小,但这只会导致程序在达到限制时崩溃。我担心当我有一个更复杂的世界时,这种行为将成为一个性能问题,有没有办法使用光泽这样这不会是一个问题?或者我使用错误的工具来完成工作?

1 个答案:

答案 0 :(得分:4)

谢谢,我在gloss-1.7.7.1中解决了这个问题。这是代码中典型的懒惰引起的空间泄漏,用于管理动画的帧定时。您的示例程序现在在恒定空间中运行。