Issue 476 in pyglet: Memory leak in text.Label

16 views
Skip to first unread message

codesite...@google.com

unread,
Mar 29, 2010, 2:39:38 AM3/29/10
to pyglet...@googlegroups.com
Status: New
Owner: ----

New issue 476 by remy.bl...@pobox.com: Memory leak in text.Label
http://code.google.com/p/pyglet/issues/detail?id=476

The following program leaks about 300 KB per second on my machine (Windows
XP, Python 2.6.5, pyglet 1.1.4, NVIDIA Quadro FX 360M (but I can observe
the same on an Intel 855GME)):

--8<-------------------------------------------------------------
import pyglet

w = pyglet.window.Window()

while not w.has_exit:
w.dispatch_events()
w.clear()
l = pyglet.text.Label("abc", font_size=w.height,
x=w.width/2, y=w.height/2,
anchor_x="center", anchor_y="center")
l.draw()
w.flip()
pyglet.clock.tick()
--8<-------------------------------------------------------------

I know I shouldn't be creating labels in the loop, but this test case was
extracted from a larger application that runs for several hours, and
creates a number of labels during its execution. Currently, the application
dies after 2 hours from memory exhaustion, when it should run for 8 hours
straight.

The memory leak remains even if I move the creation of the Label outside of
the loop, and change one of the font attributes in the loop (font name,
size, bold or italic). If I only change the text, there is no memory leak.

I tried using HeapPy to find the leaked objects, but it consistently
returns a constant memory usage, so this is really leaked memory, not
object accumulation (e.g. in a cache).

As a workaround, I ended up caching and re-using Label objects by font, so
that the font is never changed on a once-created Label. This reduced the
leak to a minimum. There still is some leakage, but it is acceptable for my
application, and could be due to a completely different cause.


--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

codesite...@google.com

unread,
Mar 29, 2010, 12:42:46 PM3/29/10
to pyglet...@googlegroups.com

Comment #1 on issue 476 by oresmus: Memory leak in text.Label
http://code.google.com/p/pyglet/issues/detail?id=476

(For more info and discussion, see the recent thread in pyglet-users with
subject
"Memory leak in text.Label".)

Reply all
Reply to author
Forward
0 new messages