memory leak
Our development efforts are being stymied by an apparent resource leak in pyglet.text. Run the following, and watch your memory consumption soar:import random import gc from pyglet import window, clock, text from pyglet.gl import * w = window.Window() l = text.Label("", font_size=w.height, x=w.width/2, y=w.height/2, halign="center", valign="center") f = clock.ClockDisplay() while not w.has_exit: w.dispatch_events() w.clear() l.text = "".join(map(lambda x: random.choice("abcdef"), xrange(3))) l.draw() f.draw() w.flip() gc.collect() clock.tick()
(log in to comment)
Comments
Good luck.
I see it is in pyglet 1.1 - it wasn't in 1.0.
It's easy to just make assumptions about code, but its better to back them up with experiments. From my experiments, resetting text on pyglet.font.Text does not leak (testing on TRUNK) - contrary to your assumption. This could be explained by side effects on setting text inside Font - many other curious things occur, notably:
self._layout.begin_update() ... self._layout.end_update()
I've managed to trace most references of group in batch, but there's still one left, so I haven't been able to fix it completely yet. In a "real-life" program this should not be (as much of a) a problem. If it is, manually hold onto the font references yourself (using pyglet.font.load).
adam: I haven't received a bug report about width on Text.
djfroofy_c_ on 2008/04/01 14:46:
Yep. It looks like you're using pyglet 1.1 which is `alpha'. You guys should report a bug on this since your code is concise and to the point (try pyglet mailing list). Or better yet, patch pyglet and submit your patch ;) If you don't want to downgrade, there is an obvious workaround (depending on the complexity of your real use case) - I'll leave this as an exercise to the reader.
Cheerio - back to tearing the flesh off of my worthless competitors.