Since the release of QuickBox2D 1.0 two bugs were discovered by numerous developers. The first bug was the inability to properly destroy group objects. The second bug was a small memory leak that caused most QuickObjects to remain in memory. Both of these bugs are now resolved.
Testing the memory leak. In QuickBox2D 1.0 if you created and destroyed 100s of rigid bodies, the ram would very slowly rise... Sometimes it would get garbage collected, but the memory would never fully be released. I created a simple test to make sure this is fixed in 1.1:
-
import com.actionsnippet.qbox.*;
-
-
var sim:QuickBox2D = new QuickBox2D(this, {debug:false});
-
-
sim.createStageWalls();
-
-
var levelParts:Array = [];
-
const TWO_PI:Number = Math.PI * 2;
-
-
// destroys and then creates a bunch of rigid bodies
-
// called every second
-
buildRandomLevel();
-
setInterval(buildRandomLevel, 1000);
-
-
var txt:TextField = TextField(addChild(new TextField()));
-
txt.x = txt.y = 30;
-
txt.backgroundColor = 0xFFFFFF;
-
sim.start();
-
-
// display amount of ram used, to make sure garbage collection is working
-
sim.addEventListener(QuickBox2D.STEP, onStep);
-
function onStep(evt:Event):void{
-
txt.text = (System.totalMemory / 100000).toFixed(2) + "mb";
-
}
-
-
function buildRandomLevel():void{
-
// destroy all rigid bodies
-
for (var i:int = 0; i<levelParts.length; i++){
-
levelParts[i].destroy();
-
}
-
levelParts = [];
-
// create a bunch of circles and boxes
-
for (i = 0; i<16; i++){
-
var rad:Number = 0.4 ;
-
levelParts.push(sim.addCircle({x:1 + i * rad * 4, y : 2, radius:rad - Math.random()*0.3}));
-
-
var rot:Number = Math.random() * TWO_PI;
-
levelParts.push(sim.addBox({x:4+Math.random() * i * 2, y:4+Math.random()*i,
-
width:3, height:0.25, angle:rot, density:0}));
-
}
-
}
This snippet creates and destroys a bunch of rigid bodies again and again.... On my macbook 2.6 Ghz intel core duo... the ram runs between 79mb and 112mb. I let it run for 40 minutes and this did not change - it always eventually returned down to 79mb.
Thanks to all the people who gave feedback that lead to the discover of these bugs.