Last active
August 29, 2015 14:02
-
-
Save spillz/088b7b5ec0ddc4f16eb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#simple program to illustrate potential memory leak (circular reference?) with pyglet | |
import pyglet | |
from pyglet.gl import * | |
import gc | |
gc.set_debug(gc.DEBUG_LEAK) | |
window = pyglet.window.Window() | |
glClearColor(0.2, 0.4, 0.5, 1.0) | |
batch = pyglet.graphics.Batch() | |
vl = None | |
def on_draw(*args): | |
global vl, batch | |
if vl is not None: | |
vl.delete() | |
batch = pyglet.graphics.Batch() ##COMMENT THIS LINE TO AVOID THE LEAK | |
#gc.collect() ##OR UNCOMMENT THIS ONE | |
print gc.garbage | |
vl = batch.add(6*1000, gl.GL_TRIANGLES, None, | |
('v2f/static', [200, 100, 200, 200, 100, 200, | |
300, 100, 300, 300, 100, 300 | |
]*1000)) | |
glClear(GL_COLOR_BUFFER_BIT) | |
glColor3f(0, 0, 0) | |
batch.draw() | |
pyglet.clock.schedule_interval(on_draw, 1.0 / 60) | |
pyglet.app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This produces stderr like: