|
|
Memory issues: Does removeLastSpace work?Hi all panoramists, I'm working on a project where a couple of panorama tours will be used by the public for long durations without computer restarts, so good memory management is vital. When I try the sample panoramas and xml for PanoSalado Rev 128 the RAM is increasing for every new panorama i load. When use larger panoramas it takes only 10-20 panorama loads for the Flash Player to consume 1gb RAM making everything unbearably sluggish. I tried both on stand alone and embedded Flash Player 10 with same results (Leopard and XP). Before i venture deeper into the code: Can anyone confirm that removeLastSpace actually works for them? Thanks a bunch - that ominous dealine is quickly approaching... Erik
|
re: PanoSalado Memory issues: Does removeLastSpace work?
Hi all panoramists
Hi Erik:
We're panographers!
Are you able to run a debug version (a la FlashTracer/Firefox, or just your flashlog) of Flash?
When I do, I see that the
removeLastSpaceis getting called -- andremoveLastSpacedoes pretty much everything it can to get the displayobjects, bitmaps, viewports, etc out of the way.Here's the corresponding AS from PanoSalado.as:
{
if (viewports.numChildren > 1 )
{
trace("PS: removeLastSpace:"+lastSpace);
var spaceToRemove:Object = getSpaceByName(lastSpace);
if (spaceToRemove.viewport.interactiveSceneManager)
spaceToRemove.viewport.interactiveSceneManager.removeEnterFrameListener();
viewports.removeChild( viewports.getChildByName( lastSpace ) );
spaceToRemove.viewport.destroy();
//spaceToRemove.viewport. = null;
var objects:Array = spaceToRemove.scene.objects;
var len:int = objects.length;
for ( var j:int=0; j < len; j++ )
{
var obj:DisplayObject3D = objects[ j ];
if (obj.materials)
{
for each( var mo3d:MaterialObject3D in obj.materials.materialsByName )
{
if (mo3d is BitmapMaterial)
{
BitmapMaterial(mo3d).destroy();
}
else { mo3d.destroy(); }
}
}
else
{ // object has only one material accessed this way:
var mat:MaterialObject3D = obj.material;
if (mat is BitmapMaterial)
{
BitmapMaterial(mat).destroy();
}
else { mat.destroy(); }
}
obj = null;
}
spaceToRemove.renderer.destroy();
spaceToRemove.scene = null;
spaceToRemove.camera = null;
if (spaceToRemove.stats)
spaceToRemove.stats = null;
spaces.splice(spaces.indexOf(spaceToRemove), 1);
spaceToRemove = null;
}
else trace("PS: removeLastSpace: there is no last space to remove");
}
I think we're doing about all we can do to clean up after ourselves; after this, it's up to Flash to deallocate the memory and/or garbage collect.
One thought would be to use
delete, to remove the space/children. Are you compiling things out yourself? You might give that a go & keep us posted...Cheers,
Patrick
Patrick Cheatham
FlashPanos.com creator, Panoramic Photographer
Got PanoSalado?
Seen same memory issues
I'd noted the same memory buildup with Firefox 3 and my own Riversong pano sets. After about 10 scenes, the memory usage was over 1gb and it took Firefox about two or three minutes to fully unload. I'm being careful to use the removeLastSpace command, because without it, the third scene would never load (it seemed to limit itself to two). I'd noted that when I didn't use removeLastSpace properly, I could still see the previous scene underneath the new one (where the older scene was taller vertically than the new one, and with a zoomed out view). When two scenes were loaded, the pan/tilt was VERY slow. So I'm sure I'm using removeLastSpace properly, but it sure doesn't seem to be removing it from MEMORY, only from the drawing process.
--Brandon
Split Infinity Music
Actual display of mem usage
I navigated thru my scenes (my Riversong site with about five hotspot-linked panos) while running the Task Manager, and annotated a screen capture. It's pretty clearly burning memory up pretty fast.
http://riversong.pragnet.org/panosalado_memory_usage.gif
Then I ran the same test on IE6. Using the same sequence, I got the same exact results, except that IE didn't release the memory when I loaded about:blank; I had to close the entire browser.
Also of note, my browsers are running Shockwave Flash 9.0 r124.
I find it interesting that the memory "leaks" even when I return to a previously visited image/space/scene (whatever it should be called).
--Brandon
Split Infinity Music
Multiple panoramas without memory buildup anyone?
Thanks for your swift feedback Patrick+Brandon,
I've tried this both on compiles of my own and your binaries with the same sad results. There's no question that the removeLastSpace() function is being called. I also agree that it seems to try to do a good job of cleaning up. That actually makes me even more worried
I'd still like to hear from someone who can confirm that they have used PanoSalado to sequentially load multiple panoramas without this memory buildup.
In case more people have this problem... I'm not a super-experinced Flash developer but here are some possible scenarios:
1. PanoSalado/Papervision isn't cleaning up properly, so not all objects are made unreachable (or bitmaps are not disposed of) and therefore are not eligible for garbage collection
2. Bitmaps are disposed of and objects are made unreachable but the Flash garbage collection for some reason chooses not to intervene (why?)
3. Something else: Flash Player versions use different garbage collection schemes? Ghost in the machine?
In case the problem persists, I was thinking of trying to modify the code to re-use a single space and just load different bitmaps into the same objects instead of using an array of spaces. This would be a lot of work (and break transitions i think) and is really just a hunch. Any thoughts?
E
Garbage collectors in Flash
I am most definitely NOT a real Flash developer, but I did quickly find this info:
It has to be clear to developers that the garbage collector doesn't delete an object from memory immediately. An object remains active for some time and it will keep going listening to and launching events until it will be definitely cancelled.
The biggest risk to create memory leaks comes from event listeners; in actionscript 3.0 has been added the chance to create listeners with weak reference, that is they will not be considered in reference counting.
from this page:
http://blog.comtaste.com/2008/04/garbage_collector_in_flash_pla.html
which has a more extensive discussion of weak references. Might be worth reviewing. In particular, I recognize that this script is chock-full of event listeners, so there might be a real possibility that this is what's holding up the collector.
--Brandon
Split Infinity Music
Garbage Collection
keep an eye on this bug from adobe:
http://bugs.adobe.com/jira/browse/FP-44?actionOrder=desc
Adobe has basically ignored this issue, and has even marked this issue as resolved at least once. This is still an issue and may be the reason behind some of the problems stated above. The 'removeLastSpace()' cleanup method may indeed get called, but there's no guarantee it's actually doing the work. Memory cleanup in flash (especially in IE) has a long way to go.
They supposedly 'fixed' the issue with the new FP10's unloadAndStop() method, which can be called to free resources (remove listeners, etc.) but so far I'm not impressed with the results.
Mem usage resets on new page
I did another quick check... when I navigate to a link that loads a new set of spaces (one that loads a new XML file, and thus closes down the current instance of flash) the memory usage drops. This is true even when I've got other things loaded that use flash - like the Google Maps website.
So it seems that a workaround is to avoid massively linked XML files, and simply use small environments with only a few rooms.
Of course that is frustrating - because the smooth and quick and tweened transitions between spaces within a single environment is one of the beautiful things. So I hope a real fix can be found.
--Brandon
Split Infinity Music
re: Memory issues: Does removeLastSpace work? (yes, it does)
Hi again:
After speaking with Zephyr, we've figured out that this is actually a Papervision issue... Zephyr keeps 'fixing' it, so that it releases the memory, and then a new rev of Papervision means Z needs to fix it again.
Look for the fix soon, in our own code repository.
Cheers,
Patrick
Patrick Cheatham
FlashPanos.com creator, Panoramic Photographer
Got PanoSalado?
re: Memory issues: Does removeLastSpace work? (yes, it does)
It figures... It's good you found the culprit.
I'm sticking with a hack that reloads browser pages for now. It works pretty good for the moment actually. (Thanks Brandon for pointing out the obvious. Sometimes an ugly hack is better than several long days of memory-safari in the Papervision jungle.)
Cheers,
E
re: Memory issues: Does removeLastSpace work? (yes, it does)
Hey Erik:
Cool!
Be sure to let us know when your project goes live!
Cheers,
Patrick
Patrick Cheatham
FlashPanos.com creator, Panoramic Photographer
Got PanoSalado?
New rev of PanoSalado source, including memory usage fixes
Hey Folks:
Head on over to http://panosalado.com and check out the nice API reference, and links to new downloads of sources for PanoSalado. Goodness abounds!
Cheers,
Patrick
Patrick Cheatham
Forum Administrator