Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop Gloss requiring an increasing amount of memory?

I'm using gloss to create am RTS game in Haskell, but I've noticed that even a very simple program will occupy more and more memory as it runs. The following program, for example, will gradually increase its memory use (it will require ~0.025mb per second ).

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))

I've tried limiting the heap size at runtime but that just causes the program to crash when it hits the limit. I'm concerned this behaviour will become a performance issue when I have a more complex world, is there a way to use gloss such that this won't be an issue? Or am I using the wrong tool for the job?

like image 461
Chironex Avatar asked Oct 06 '22 22:10

Chironex


1 Answers

Thanks, I fixed this in gloss-1.7.7.1. It was a typical laziness-induced space leak in the code that manages the frame timing for animations. Your example program now runs in constant space.

like image 164
Ben Lippmeier Avatar answered Oct 18 '22 19:10

Ben Lippmeier