Memory leak problem of window mode

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Memory leak problem of window mode

#1 Post 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.
Last edited by nyaatrap on Wed Dec 26, 2012 2:11 am, edited 2 times in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

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

#2 Post by PyTom »

What do the sprites look like? Are you ever hiding the sprites you show?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

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

#3 Post 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)

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

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

#4 Post 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

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

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

#5 Post 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
Last edited by nyaatrap on Tue Jan 01, 2013 10:57 pm, edited 1 time in total.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

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

#6 Post 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.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Memory leak problem of window mode

#7 Post by PyTom »

Can you file a github bug on this, please?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom


Post Reply

Who is online

Users browsing this forum: No registered users