New issue 169 by davexu...@gmail.com: Tile maps cause memory leaks
http://code.google.com/p/los-cocos/issues/detail?id=169
What steps will reproduce the problem?
1. Run the code below (put the .py file in the test/ directory as it is
based off of the test_tiles.py test)
2. Open top or another process manager and watch as memory consumption goes
up.
Here is the test:
# This code is so you can run the samples without installing the package
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import pyglet
from pyglet.window import key
from pyglet.gl import *
pyglet.resource.path.append(pyglet.resource.get_script_home())
pyglet.resource.reindex()
import cocos
from cocos import tiles, actions, layer, scenes
def make_scene():
scroller = layer.ScrollingManager()
test_layer = tiles.load('road-map.xml')['map0']
scroller.add(test_layer)
return cocos.scene.Scene(scroller)
if __name__ == "__main__":
from cocos.director import director
director.init(width=600, height=300, do_not_scale=True, resizable=True)
def new_scene(dt):
director.replace(cocos.scenes.transitions.FadeTransition(make_scene(), 1))
pyglet.clock.schedule_interval(new_scene, 3)
director.run(make_scene())
What is the expected output? What do you see instead?
The output is correct but I expect the tile map data to be garbage
collected but it doesn't seem to be happening. As far as I can tell, other
layers that I have used do not have this issue. Memory output jumps up
around 10MB for each scene change and the program quickly uses hundreds of
MB of memory.
What version of the product are you using? On what operating system?
Tested on 0.4.0 and 0.5.0rc0
Forgot to mention operating system. I am using Arch Linux.
Comment #2 on issue 169 by ccanepacc: Tile maps cause memory leaks
http://code.google.com/p/los-cocos/issues/detail?id=169
Confirmed in windows xp sp3, python 2.6.6, cocos 0.5rc0, pyglet 1.2dev and
pyglet 1.1.4 release.
Eliminating the transition does not help.
Need to investigate.
Comment #3 on issue 169 by ccan...@gmail.com: Tile maps cause memory leaks
http://code.google.com/p/los-cocos/issues/detail?id=169
Ok, the ultimate cause is that both ScrollingManager and ScrollableLayer
are doing
director.push_handlers(self.on_cocos_resize)
in their on_enter method, but not a balancing pop in on_exit.
That keeps references to the instances in director._event_stack even when
the scene goes inactive.
If we add a pop at on_exit, the layers will miss notifications about window
resize while they are inactive, so we need to ensure that at each on_enter
we have code that handles resizes that happened when the nodes were not in
the active scene.
I will look at the code and modify some test(s) in issue 153 (they exercise
scrolling, both with and without tilemaps), then look for well behaved
fixes.
Comment #4 on issue 169 by ccan...@gmail.com: Tile maps cause memory leaks
http://code.google.com/p/los-cocos/issues/detail?id=169
fixed at r1169
attached specific test, fails with r1168, pass with r1169