On Tue, Dec 22, 2009 at 10:36 AM, Hello3171 <[email protected]> wrote:
> So once all sprites which reference a texture are destroyed, the
> texture will be removed by itself whenever (by the gc)?

So long as nothing else references that texture, yes. However there is
no way to tell how long that will take. Though in many cases that is
not important.

> To be clear, in these scenarios:
>
> #my object does this
> sprite = pyglet.sprite.Sprite(texture)
>
> If I have one single reference to this object and I delete this
> reference, the object should be free to be garbage collected. And when
> this happens the sprite should be garbage collected. I do not need to
> call sprite.delete()
>
> 2#My object does this:
> sprite = pyglet.sprite.Sprite(texture, batch=batch)
>
> In this case I do need to call sprite.delete() to remove the sprite
> from the sprite batch, only then can it be garbage collected.
>
> OR is it more appropriate to do this:
>
> sprite.batch = None
>
> This would remove it from the batch?

The batch does not contain a reference to the sprite. The batch is a
place for the sprite to store its vertex list. When you are using a
batched sprite, you should call sprite.delete() when you are done with
it, otherwise it's vertex list may remain in the batch for a while
until the sprite object is collected. This could cause a "ghost" of
the sprite to continue to be drawn until collection actually occurs.

Note the docstring for Sprite.delete:

        '''Force immediate removal of the sprite from video memory.

        This is often necessary when using batches, as the Python garbage
        collector will not necessarily call the finalizer as soon as the
        sprite is garbage.
        '''

-Casey

--

You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.


Reply via email to