away3d / away3d-core-broomstick

Away3D engine for Flash Player Incubator
http://www.away3d.com
93 stars 25 forks source link

Memory leak in RenderableListItemPool #63

Open pigiuz opened 13 years ago

pigiuz commented 13 years ago

I experienced a memory leak in the rendering process. After a render call renderables still were refrenced by RenderableListItem s and RenderableListItem s still had references to the next.

I fixed the leak by adding a function resetIndex to RenderableListItemPool, editing the function freeAll in RenderableListItemPool, and changing the calls EntityCollector performs to _renderableListItemPool instance.

Here's the changes:

RenderableListItemPool.as:

ADDED public function resetIndex():void { _index = 0; }

EDITED public function freeAll() : void { var item:RenderableListItem; while(_index-->0){ item = _pool[_index]; item.renderable = null; item.next = null; } }

EntityCollector.as

[EDITED] public function clear() : void { _numTriangles = _numMouseEnableds = 0; _blendedRenderableHead = null; _opaqueRenderableHead = null; _renderableListItemPool.resetIndex(); // << call resetIndex instead of freeAll if (_numLights > 0) _lights.length = _numLights = 0; }

[EDITED] public function cleanUp() : void { if (_numEntities > 0) { for (var i : uint = 0; i < _numEntities; ++i) _entities[i].popModelViewProjection(); _entities.length = _numEntities = 0; _renderableListItemPool.freeAll(); // << added! } }

ciao, pigiuz