A possible memory leak or a bug with billboards removal?

Hey guys, it’s been a while…

I was debugging some memory leaks on my side and during my Heap Profiles, I think I’ve discovered a potential memory leak in Cesium.

It could be nothing but my hunch tells me there’s an issue. When I remove entities from a DataSource’s EntityCollection, those entities are still retained if

they have billboards associated with them. This does not occur with entities without billboards. Let me explain :

This Sandcastle code will demonstrate the proper disposal of an entity without a billboard. (Steps are below)

var viewer = new Cesium.Viewer(‘cesiumContainer’);

Sandcastle.addToolbarButton(‘Remove entity’,function(){

viewer.entities.removeById(‘myId’);

});

var someEntity = viewer.entities.add({

id :‘myId’,

name : ‘This polyline will not leak’,

polyline : {

positions : Cesium.Cartesian3.fromDegreesArray([-75, 37,

-125, 37]),

width : 10,

material : new Cesium.PolylineGlowMaterialProperty({

glowPower : 0.2,

color : Cesium.Color.BLUE

})

}

});

``

  1. Run the example

  2. Take a heap snapshot, you will see a single Entity as expected

  1. Click ‘Remove entity’ and take another heap snapshot. You will see no instances of Entity (as expected)

Now the weird part about billboards :

Use the following code :

var viewer = new Cesium.Viewer(‘cesiumContainer’);

Sandcastle.addToolbarButton(‘Remove entity’,function(){

viewer.entities.removeById(‘myId’);

});

var glowingLine = viewer.entities.add({

id :‘myId’,

name : ‘This billboard is a suspect’,

position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),

billboard :{

image : ‘…/images/Cesium_Logo_overlay.png’

}

});

``

  1. Run the example

  2. Take a heap snapshot, you will see the same result as with the polyline example, having 1 instance Entity

  3. Click ‘Remove entity’ and take another heap snapshot, you will see there’s still 1 instance of Entity retained, though no EntityCollection points to it, neither it is seen.

My research so far :

  1. The entity is retained by _pickObjects of a Context.

  2. It seems that the PickId is not destroyed thus retaining the entity that it keeps.

3.The PickId is not destroyed since the billboard was not destroyed when the entity was removed

In my tests I was running with many entities that I was adding and removing. And each time the Entity number would increase, but never decrease, that’s why I believe

it is a problem.

Let me know if further explanations are needed,

Thanks,

-Mati O

I saw something similar. BillboardVisualizer seems to hold onto the Billboard instances in order to reuse them, and although it's clearing some fields in its returnBillboard function, it doesn't clear the billboard.id, which is the Entity. Eventually when the Billboard is reused, the id gets overwritten and the previous entity should then be released. I fixed this in my local copy of cesium by adding

billboard.id = undefined;

to returnBillboard.

Thanks for looking into this!

I’d rather not modify Cesium’s code but maybe implement my own billboard visualizer that will take care of the release of the entity.

Thanks again for sharing this info, it will come handy if I will tackle it on my side instead of waiting for an official solution (if there’s any…)