Page 1 of 1

DynamicDisplayable memory leak?

Posted: Thu Dec 30, 2010 8:00 am
by jack_norton
Haha today I'm going to spam the Renpy development section :D
I found a really strange bug. First of all, since my "RPG framework" is insanely complex (really pushing renpy to its limits) it might be my fault. However, I don't know if just using the standard renpy commands I can cause a memory leak? :shock:
The memory leaks happens if you use DynamicDisplayable. I use it for tooltips.

Code: Select all

init python:
    class Tooltip(object):
        def __init__(self,id):
            self.id=id;self.ok=None;self.bk=renpy.store.tipT
        def show(self):
            self.ok = True
            renpy.store.tipT=self.id
        def hide(self):
            if self.ok:
                renpy.store.tipT=self.bk
                self.ok = False

    def TTipMaster(st,at):
        mollusk=None
        mollusk=ui.frame(yalign=0.995,yminimum=16,ymaximum=16,xmaximum=1020, xminimum=1020,xfill=True,style="inv")
        ui.text(renpy.store.tipT,size=16,xalign=0.5)
        return mollusk, .2
init:
    image Toolz = DynamicDisplayable(TTipMaster)
then in my main battle loop I do: renpy.show("Toolz")
That's it - if I comment the show statement, everything works fine (but obviously I don't see a tooltip). If I leave the PC on with tooltip enabled, using windows Task Manager I see renpy.exe process that gradually eats more RAM, which usually means a memory leak. After some minutes (without doing anything) the game crashes, sometimes forcing a hard reset of the PC :(
I never noticed it before because when I am out of combat, somehow it resets, or when I use Shift+R to reload the code it also "resets".
As I said, might be some weird stuff I'm doing somewhere else in my code, but I never had a memory leak crash before in all my other customized renpy games... :(

Re: DynamicDisplayable memory leak?

Posted: Thu Dec 30, 2010 9:19 am
by jack_norton
Just wanted to add that I tried with a very simple renpy app that has just the lines above (plus obviously a button with associated tooltip) and I see the memory leak, so I'm fairly confident that it's a memory leak in that point. I am not sure if it's a bug in renpy dynamicdisplayable or in the way I use it...

Re: DynamicDisplayable memory leak?

Posted: Thu Dec 30, 2010 10:15 am
by PyTom
The problem here is that each call to ui.frame adds a new ui.frame to the screen. (Although since renpy.restart_interaction isn't called, it isn't shown.)

You need to call ui.detached before calling ui.frame, so it isn't added.

Re: DynamicDisplayable memory leak?

Posted: Thu Dec 30, 2010 10:48 am
by jack_norton
ah lol thanks, I didn't notice was added twice because the background was covering previous one!! :)