For a start, you shouldn’t re-create a stimulus on every frame. This takes a lot of time (if not memory). You should create your score_text
variable just once, and then in your drawing loop, you just update its properties as required. e.g.
score_text.text = score_update
Now there is a known underlying memory leak in a library that we rely on (pyglet
) in precisely this situation (rapidly updating the text value of a text stimulus). This might be what you are encountering. I know @jon is at work on developing a new text stimulus that would avoid this limitation in pyglet
and hopefully that won’t be too far away.