Page 1 of 1

Is there a memory leak in 'renpy.Render.canvas()'?

Posted: Fri Jan 12, 2024 7:08 pm
by ToxicTractor
Hello!

Let me start by providing a little context. I was playing around with creator-defined displayables and was trying to create a simple, paint-like minigame. I noticed that RenPy seemed to slow down considerably after some time, and it turns out it was using more than 10 gigabytes of memory.

I searched around to figure out if others have had this issue, but I was unable to find anything.

I was able to narrow the issue down to this: Accessing the canvas of the render object by calling 'renpy.Render.canvas()' and then redrawing the screen using 'renpy.redraw(self, 0)' will cause memory usage to build up. The weird thing is that it doesn't actually seem to crash but stops just shy of using 100% of my system's memory.

I realise that this might be caused by me doing something wrong, but I have no idea what it is. The code below is a very simple demonstration of the problem. Does anyone know what is going on here?

Code: Select all

init python:
    
    class MyCDD(renpy.Displayable):
        def __init__(self):
            renpy.Displayable.__init__(self)


        def render(self, width, height, st, at):
            r = renpy.Render(width, height)
            
            canvas = r.canvas() ## this seems to be the cause

            canvas.circle("#f00", self.mousePos, 20) ## the issue persists even if I remove this line

            renpy.redraw(self, 0)

            return r


screen testscreen:
    modal True

    add MyCDD()


label start:
    show screen testscreen

    pause