Page 1 of 1

Memory leak problem of window mode

Posted: Mon Dec 24, 2012 5:55 am
by nyaatrap
I made a sprite gallery and noticed a memory leak problem of showing sprites. The gallery code is really simple:

Code: Select all

label sprite_gallery:
    $config.rollback_enabled = False
    while True:
        #$ renpy.free_memory()
        $ (char,face,pose)=renpy.call_screen("sprite_gallery")
        $ renpy.scene()
        $ renpy.show("%s %s %s"%(char,face,pose))
It just call the screen which has lists of image names, then show sprites using the return values.
The problem is, changing sprites never release caches and it'll soon crash reaching 2GB RAM consumption.
Sprites are composited by im.Composite or LiveComposites. I tried both way but the result is the same.
I tried jump instead of while, or replaced renpy.show as show expression, but no difference.
Image cache is set to 8, but it's ignoring this limit. Only solution is calling renpy.free_memory every time.

Edit: It's probably window mode issue.

Re: Memory leak problem of renpy.show regardless of cash siz

Posted: Mon Dec 24, 2012 10:52 am
by PyTom
What do the sprites look like? Are you ever hiding the sprites you show?

Re: Memory leak problem of renpy.show regardless of cash siz

Posted: Mon Dec 24, 2012 1:22 pm
by nyaatrap
Unfortunately, putting renpy.hide doesn't change leaking. I also forced the software renderer, but it's still leaking. Sprites are 1536px*2 layers and the code is following":

Code: Select all

init python:
    expressions = ["neutral", "happy", "proud", "grin", "wink", "laugh", "laughcry", "serious", "focus", "angry", "mad",
        "thinking", "disgusted", "bashful", "kissing", "worried", "embarrassed", "sad", "TT", "pain", "scream", "OO", "surprised"]
    for i in expressions:
        for j in ["1","2"]: #pose1 and pose2
            renpy.image(("akari", "%s%s"%(i,j)),  ConditionSwitch(
                "akari_cos==0", im.Composite((810,1536), (0,0), "small/akari0_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==1", im.Composite((810,1536), (0,0), "small/akari1_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==2", im.Composite((810,1536), (0,0), "small/akari2_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==3", im.Composite((810,1536), (0,0), "small/akari3_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==4", im.Composite((810,1536), (0,0), "small/akari1_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==5", im.Composite((810,1536), (0,0), "small/akari2_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==6", im.Composite((810,1536), (0,0), "small/akari3_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==11", im.Composite((810,1536), (0,0), "small/akari11_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==12", im.Composite((810,1536), (0,0), "small/akari12_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==13", im.Composite((810,1536), (0,0), "small/akari13_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==21", im.Composite((810,1536), (0,0), "small/akari21_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==22", im.Composite((810,1536), (0,0), "small/akari22_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j)),
                "akari_cos==23", im.Composite((810,1536), (0,0), "small/akari3_%s.png"%j, (0,0), "small/akari_%s_%s.png"%(i,j))))
I removed ConditionSwitch and tested with only the first line - but it's the same.
I'll send my game file in PM if you want to look up (though it's a large developing game. scripts and assets are complicated and not organized)

Re: Memory leak problem of renpy.show regardless of cash siz

Posted: Mon Dec 24, 2012 4:37 pm
by nyaatrap
In fact, I'm having this cache issue long time on GFX made with anim.Filmstrip. When threy're shown and later hidden, those memory cache won't be freed unless renpy.free_memory is manually called. Only when renpy.free_memory is called, cash size is returned to the proper size defined by config.image_cache_size

Re: Memory leak problem of renpy.show regardless of cache si

Posted: Tue Dec 25, 2012 6:06 am
by nyaatrap
[Edit: this issue is fixed, but i leave the code as a part of reference]
Here is the test code of sprite gallery.
The code is quite simple. It's just added several statements on the template:

Code: Select all

# You can place the script of your game in this file.

init python:        
    
    config.image_cache_size=1
    
    for k in ["1","2", "3"]:
        for j in ["1","2","3","4","5", "6"]:
            for i in ["a", "b", "c", "f", "l", "n", "p", "s", "z"]:
                renpy.image(("rio", "%s%s%s"%(i,j,k)),
                    im.Composite((935,1280), (0,0), "char/rio.png", (0,0), "char/rio_%s.png"%i, (0,0), "char/rio_x%s.png"%j, (0,0), "char/rio_xx%s.png"%k))
                
    for k in ["1","2", "3"]:
        for j in ["1","2","3","4","5","6"]:
            for i in ["a", "b", "c", "f", "l", "n", "p", "s", "z"]:
                renpy.image(("elis", "%s%s%s"%(i,j,k)),
                    im.Composite((878,1280), (0,0), "char/elis.png", (0,0), "char/elis_%s.png"%i, (0,0), "char/elis_x%s.png"%j, (0,0), "char/elis_xx%s.png"%k))
                
screen sprite_select:
    vbox align(0.0,0.0):
        for i in ["a", "b", "c", "f", "l", "n", "p", "s", "z"]:            
            textbutton i action Return((char, i, mouth, cheek))   
    vbox align (0.0, 1.0):
        for i in ["1","2","3"] :
            textbutton i action Return((char, eyes, mouth, i))   
    vbox align(1.0,0.0):
        for i in ["1","2","3","4","5","6"]:            
            textbutton i action Return((char, eyes, i, cheek))   
    vbox align(1.0,1.0):
        for i in ["rio","elis"]:            
            textbutton i action Return((i, eyes, mouth, cheek))           
                
# The game starts here.
label start:
    python:
        char="rio"
        eyes="n"
        mouth="1"
        cheek="1"
        config.rollback_enabled = False
    while True:
        #$ renpy.free_memory()
        $ (char,eyes,mouth,cheek)=renpy.call_screen("sprite_select")
        hide rio
        hide elis
        $to_show=char+" "+eyes+mouth+cheek
        show expression to_show:
            xalign .5 yalign .4
    return

Re: Memory leak problem of renpy.show regardless of cache si

Posted: Wed Dec 26, 2012 2:05 am
by nyaatrap
OK, I found the condition:
1) Fullscreen mode => no leak
2) Window mode => leaks

Changing GPU/software renderer doesn't change the result. I don't know it's my PC's problem (Windows7 Intel GPU) or not.

Edit: Both full screen mode and window mode keep image cache until ren'py get an out of memory error. Changing the window mode or minimizing the window is the only way to release image cache. Unless mode isn't switched, ren'py never releases image cache.

Re: Memory leak problem of window mode

Posted: Wed Dec 26, 2012 2:37 pm
by PyTom
Can you file a github bug on this, please?

Re: Memory leak problem of window mode

Posted: Wed Dec 26, 2012 7:22 pm
by nyaatrap