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
})
}
});
``
-
Run the example
-
Take a heap snapshot, you will see a single Entity as expected
- 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’
}
});
``
-
Run the example
-
Take a heap snapshot, you will see the same result as with the polyline example, having 1 instance Entity
-
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 :
-
The entity is retained by _pickObjects of a Context.
-
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