Skip to content

Instantly share code, notes, and snippets.

@spillz
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spillz/088b7b5ec0ddc4f16eb2 to your computer and use it in GitHub Desktop.
Save spillz/088b7b5ec0ddc4f16eb2 to your computer and use it in GitHub Desktop.
#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()
@spillz
Copy link
Author

spillz commented Jun 1, 2014

This produces stderr like:

    gc: collectable <instancemethod 0x9831d4c>
    gc: collectable <c_byte_Array_128 0xb747fa4c>
    gc: collectable <dict 0x98411c4>
    gc: collectable <cell 0x9830adc>
    gc: collectable <cell 0x9830af4>
    gc: collectable <tuple 0x983cdcc>
    gc: collectable <function 0x8f93e2c>
    gc: collectable <Batch 0x9838aac>
    gc: collectable <dict 0x983aa44>
    gc: collectable <list 0x9838a2c>
    gc: collectable <dict 0x983a35c>
    gc: uncollectable <VertexDomain 0x9838b2c>
    gc: uncollectable <MappableVertexBufferObject 0x9838b8c>
    gc: uncollectable <VertexDomain 0x9838dcc>
    gc: uncollectable <MappableVertexBufferObject 0x9838e2c>
    gc: uncollectable <VertexDomain 0x9838fcc>
    gc: uncollectable <MappableVertexBufferObject 0x983c04c>
    gc: uncollectable <VertexDomain 0x983c1ec>
    gc: uncollectable <MappableVertexBufferObject 0x983c24c>
    gc: uncollectable <VertexDomain 0x983c3ec>
    gc: uncollectable <MappableVertexBufferObject 0x983c44c>
    gc: uncollectable <VertexDomain 0x983c5ec>
    gc: uncollectable <MappableVertexBufferObject 0x983c64c>
    gc: uncollectable <VertexDomain 0x983c7ec>
    gc: uncollectable <MappableVertexBufferObject 0x983c84c>
    gc: uncollectable <VertexDomain 0x983c9ec>
    gc: uncollectable <MappableVertexBufferObject 0x983ca4c>
    gc: uncollectable <VertexDomain 0x983cbec>
    gc: uncollectable <MappableVertexBufferObject 0x983cc4c>
    gc: uncollectable <VertexDomain 0x983cdec>
    gc: uncollectable <MappableVertexBufferObject 0x983ce4c>
    gc: uncollectable <VertexDomain 0x983cfec>
    gc: uncollectable <MappableVertexBufferObject 0x984006c>
    gc: uncollectable <dict 0x983acec>
    gc: uncollectable <dict 0x983ad74>
    gc: uncollectable <dict 0x983b35c>
    gc: uncollectable <dict 0x983b3e4>
    gc: uncollectable <dict 0x983b934>
    gc: uncollectable <dict 0x983b9bc>
    gc: uncollectable <dict 0x983bf0c>
    gc: uncollectable <dict 0x983d02c>
    gc: uncollectable <dict 0x983d57c>
    gc: uncollectable <dict 0x983d604>
    gc: uncollectable <dict 0x983db54>
    gc: uncollectable <dict 0x983dbdc>
    gc: uncollectable <dict 0x983e1c4>
    gc: uncollectable <dict 0x983e24c>
    gc: uncollectable <dict 0x983e79c>
    gc: uncollectable <dict 0x983e824>
    gc: uncollectable <dict 0x983ed74>
    gc: uncollectable <dict 0x983edfc>
    gc: uncollectable <dict 0x983f3e4>
    gc: uncollectable <dict 0x983f46c>
    gc: uncollectable <dict 0x983f9bc>
    gc: uncollectable <dict 0x983fa44>
    gc: uncollectable <dict 0x983ae84>
    gc: uncollectable <list 0x98385cc>
    gc: uncollectable <list 0x983826c>
    gc: uncollectable <Allocator 0x9838b6c>
    gc: uncollectable <c_byte_Array_65536 0x98337c4>
    gc: uncollectable <dict 0x983b4f4>
    gc: uncollectable <tuple 0x98381cc>
    gc: uncollectable <list 0x9838c6c>
    gc: uncollectable <list 0x98386cc>
    gc: uncollectable <Allocator 0x9838e0c>
    gc: uncollectable <c_byte_Array_65536 0x9833854>
    gc: uncollectable <dict 0x983bacc>
    gc: uncollectable <tuple 0x98383cc>
    gc: uncollectable <list 0x98389cc>
    gc: uncollectable <list 0x98388cc>
    gc: uncollectable <Allocator 0x983c02c>
    gc: uncollectable <c_byte_Array_65536 0x98338e4>
    gc: uncollectable <dict 0x983d13c>
    gc: uncollectable <tuple 0x98383ec>
    gc: uncollectable <list 0x98389ac>
    gc: uncollectable <list 0x9838acc>
    gc: uncollectable <Allocator 0x983c22c>
    gc: uncollectable <c_byte_Array_65536 0x9833974>
    gc: uncollectable <dict 0x983d714>
    gc: uncollectable <tuple 0x98387cc>
    gc: uncollectable <list 0x983c06c>
    gc: uncollectable <list 0x9838d6c>
    gc: uncollectable <Allocator 0x983c42c>
    gc: uncollectable <c_byte_Array_65536 0x9833a04>
    gc: uncollectable <dict 0x983dcec>
    gc: uncollectable <tuple 0x9838bcc>
    gc: uncollectable <list 0x983c26c>
    gc: uncollectable <list 0x9838f6c>
    gc: uncollectable <Allocator 0x983c62c>
    gc: uncollectable <c_byte_Array_65536 0x9833a94>
    gc: uncollectable <dict 0x983e35c>
    gc: uncollectable <tuple 0x9838e4c>
    gc: uncollectable <list 0x983c46c>
    gc: uncollectable <list 0x983c18c>
    gc: uncollectable <Allocator 0x983c82c>
    gc: uncollectable <c_byte_Array_65536 0x9833b24>
    gc: uncollectable <dict 0x983e934>
    gc: uncollectable <tuple 0x9838e6c>
    gc: uncollectable <list 0x983c66c>
    gc: uncollectable <list 0x983c38c>
    gc: uncollectable <Allocator 0x983ca2c>
    gc: uncollectable <c_byte_Array_65536 0x9833bb4>
    gc: uncollectable <dict 0x983ef0c>
    gc: uncollectable <tuple 0x983c08c>
    gc: uncollectable <list 0x983c86c>
    gc: uncollectable <list 0x983c58c>
    gc: uncollectable <Allocator 0x983cc2c>
    gc: uncollectable <c_byte_Array_65536 0x9833c44>
    gc: uncollectable <dict 0x983f57c>
    gc: uncollectable <tuple 0x983c28c>
    gc: uncollectable <list 0x983ca6c>
    gc: uncollectable <list 0x983c78c>
    gc: uncollectable <Allocator 0x983ce2c>
    gc: uncollectable <c_byte_Array_65536 0x9833cd4>
    gc: uncollectable <dict 0x983fb54>
    gc: uncollectable <tuple 0x983c48c>
    gc: uncollectable <list 0x983cc6c>
    gc: uncollectable <list 0x983c98c>
    gc: uncollectable <Allocator 0x984004c>
    gc: uncollectable <c_byte_Array_65536 0x9833d64>
    gc: uncollectable <VertexAttribute 0x9838b4c>
    gc: uncollectable <tuple 0x9838a8c>
    gc: uncollectable <dict 0x983ac64>
    gc: uncollectable <dict 0x983b02c>
    gc: uncollectable <VertexAttribute 0x9838dec>
    gc: uncollectable <tuple 0x9838d2c>
    gc: uncollectable <dict 0x983b2d4>
    gc: uncollectable <dict 0x983b604>
    gc: uncollectable <VertexAttribute 0x9838fec>
    gc: uncollectable <tuple 0x9838f2c>
    gc: uncollectable <dict 0x983b8ac>
    gc: uncollectable <dict 0x983bbdc>
    gc: uncollectable <VertexAttribute 0x983c20c>
    gc: uncollectable <tuple 0x983c14c>
    gc: uncollectable <dict 0x983be84>
    gc: uncollectable <dict 0x983d24c>
    gc: uncollectable <VertexAttribute 0x983c40c>
    gc: uncollectable <tuple 0x983c34c>
    gc: uncollectable <dict 0x983d4f4>
    gc: uncollectable <dict 0x983d824>
    gc: uncollectable <VertexAttribute 0x983c60c>
    gc: uncollectable <tuple 0x983c54c>
    gc: uncollectable <dict 0x983dacc>
    gc: uncollectable <dict 0x983ddfc>
    gc: uncollectable <VertexAttribute 0x983c80c>
    gc: uncollectable <tuple 0x983c74c>
    gc: uncollectable <dict 0x983e13c>
    gc: uncollectable <dict 0x983e46c>
    gc: uncollectable <VertexAttribute 0x983ca0c>
    gc: uncollectable <tuple 0x983c94c>
    gc: uncollectable <dict 0x983e714>
    gc: uncollectable <dict 0x983ea44>
    gc: uncollectable <VertexAttribute 0x983cc0c>
    gc: uncollectable <tuple 0x983cb4c>
    gc: uncollectable <dict 0x983ecec>
    gc: uncollectable <dict 0x983f0b4>
    gc: uncollectable <VertexAttribute 0x983ce0c>
    gc: uncollectable <tuple 0x983cd4c>
    gc: uncollectable <dict 0x983f35c>
    gc: uncollectable <dict 0x983f68c>
    gc: uncollectable <VertexAttribute 0x984002c>
    gc: uncollectable <tuple 0x983cf4c>
    gc: uncollectable <dict 0x983f934>
    gc: uncollectable <dict 0x983fc64>
    gc: uncollectable <dict 0x983abdc>
    gc: uncollectable <list 0x9838a0c>
    gc: uncollectable <list 0x983840c>
    gc: uncollectable <list 0x983846c>
    gc: uncollectable <dict 0x983b24c>
    gc: uncollectable <list 0x9838cac>
    gc: uncollectable <list 0x98387ec>
    gc: uncollectable <list 0x983864c>
    gc: uncollectable <dict 0x983b824>
    gc: uncollectable <list 0x9838eac>
    gc: uncollectable <list 0x98389ec>
    gc: uncollectable <list 0x983884c>
    gc: uncollectable <dict 0x983bdfc>
    gc: uncollectable <list 0x983c0cc>
    gc: uncollectable <list 0x9838c8c>
    gc: uncollectable <list 0x9838a4c>
    gc: uncollectable <dict 0x983d46c>
    gc: uncollectable <list 0x983c2cc>
    gc: uncollectable <list 0x9838e8c>
    gc: uncollectable <list 0x9838cec>
    gc: uncollectable <dict 0x983da44>
    gc: uncollectable <list 0x983c4cc>
    gc: uncollectable <list 0x983c0ac>
    gc: uncollectable <list 0x9838eec>
    gc: uncollectable <dict 0x983e0b4>
    gc: uncollectable <list 0x983c6cc>
    gc: uncollectable <list 0x983c2ac>
    gc: uncollectable <list 0x983c10c>
    gc: uncollectable <dict 0x983e68c>
    gc: uncollectable <list 0x983c8cc>
    gc: uncollectable <list 0x983c4ac>
    gc: uncollectable <list 0x983c30c>
    gc: uncollectable <dict 0x983ec64>
    gc: uncollectable <list 0x983cacc>
    gc: uncollectable <list 0x983c6ac>
    gc: uncollectable <list 0x983c50c>
    gc: uncollectable <dict 0x983f2d4>
    gc: uncollectable <list 0x983cccc>
    gc: uncollectable <list 0x983c8ac>
    gc: uncollectable <list 0x983c70c>
    gc: uncollectable <dict 0x983f8ac>
    gc: uncollectable <list 0x983cecc>
    gc: uncollectable <list 0x983caac>
    gc: uncollectable <list 0x983c90c>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment