That's good information.  On an SDL2 game, I was using lots of generated 
textures for simple particle effects. It sounds like this sort of thing 
would trigger the memory leak-like behavior your describe.

The addition of a no_cache parameter sounds useful to me too. I'm not 
familiar with the pyglet image module yet, but it would be a nice addition 
if it can be implemented smoothly.


On Monday, January 18, 2016 at 7:25:58 AM UTC+9, Serdar Yegulalp wrote:
>
> I've been working on a Pyglet app that creates textures dynamically rather 
> than loading them by way of resources on disk. Unfortunately, this means 
> textures have a way of piling up in memory. Fortunately, a little close 
> reading of the docs showed there's a way to force the release of cached 
> textures if you don't need them anymore.
>
> 1) Create a list to hold your textures:
>
> texture_list = []
>
> 2) Append dynamically created textures to the list.
>
> texture_list.append(pyglet.image.Texture.create( <dimensions> ))
>
> 3) When you're done with a texture, pop it off the list.
>
> texture_list.pop( <texture_index>)
>
> 4) Call pyglet.gl.get_current_context().set_current() to ensure that the 
> unused textures are purged from the _doomed_textures list in the context 
> cache.
>
> This last step is what's most important, because otherwise dynamically 
> created textures just get cached in the hope that they'll be re-used, when 
> in fact they never are in this particular scenario.
>
> Cache pileups look like a memory leak in Pyglet, and in fact for the 
> longest time I was treating it like a memory leak, when in fact it isn't -- 
> it's a by-product of Pyglet's own behaviors re: textures.
>
> One possible future suggestion (which I'll submit separately as a feature 
> request) is that textures can be created with some kind of boolean flag 
> (maybe "no_cache"?) to keep them from being cached. But for now this works.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to