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

Chi*_*nex 5 graphics haskell

我正在使用 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))
Run Code Online (Sandbox Code Playgroud)

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

Ben*_*ier 4

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