Memory usage did not reduce after remove dataSource

Hi,

I have a polygon data about 9mb I add with like this:

var polyLineDataSource = null;
function polygonLoadTR() {

  GeoJsonDataSource.load('./Apps/Cesiumviewer/trBorder.json', {
    stroke: Color.BLUE,
    fill: Color.PINK,
    strokeWidth: 3,
    markerSymbol: '?',
    clampToGround: true
  }).then(function(res) {
    polyLineDataSource = res
    viewer.dataSources.add(polyLineDataSource);
    viewer.scene.requestRender();
  })
}

function polygonDeleteTR() {
  viewer.dataSources.remove(polyLineDataSource);
  viewer.scene.requestRender();
}

When I call polygonDeleteTR function memory usage decrese a bit but not release all.

At begining memory usage about 900mb after add datasource it goes to 2gb after delete its reduce to 1.8gb

What can I do for that ?

@akkaya.hu

Welcome to the community! I am not sure if there is a way to reduce memory usage even more. Is there a particular reason why you are trying to optimize memory usage to this extent? I would love to learn more about your use case.

-Sam

I try to draw big polygon objects like borders, and when I add this objects memory usage is too high, I think entities are too big.

And I look to destroy methods then I see Its not delete propery objects. For example its empty cartesian objects, only delete some functions. I think its a bad thing.

Also cesium did not free webgl objects from property.
I mean It call:

 gl.deleteSometing(obj.someglObject)
obj.someglObject = null  <- this part is not exist and it still in object I think it can cause memory leak a bit.

ın code above in first line you can delete bufer but your buffer object still connect object property for this reason js garbage collector can not free buffer object. We delete data but we dont now actually how much memory use this gl object so you need to seperate from object property like second line with this gl object did not connect any other object and garbage can delete it.

@akkaya.hu

Thank you for providing some more details. To be candid, I do not have a significant amount of experience with memory management in WebGL.

I suggest that you upload your data to Cesium ion and stream it into CesiumJS at runtime. I suspect that this would resolve a lot of the memory-related issues that you are experiencing. Please let me know what you think.

-Sam

1 Like

@sam.rothstein

I think its about js memory management. Because in js if an object has reference in another object garbage collector did not free this object.

obj.someglObject = null

if you do that above obj.someglObject referenced webgl object but if you set null webgl object does not any reference in any variable or abject property, so garbage collector can delete it.

Same mistakes exist in remove entities. Cesium js does not delete object properly so it cause memory leak.

I create 5k geojson point randomly and :

memory usage before add:

and memory usage when 5k point added:

and finally memory usage after delete 5k point:

I can release memory of main process.

But I have another problem. I try 1k line (each line has 1k vetex) and :slight_smile:

in below after I add lines:

in below after delete lines:

As you see I release for main process but I it cant release for other process, I dont know wyh is leak, may be about wrokers I research this.

And one more thing I think for 1k line (each line has 1k vertex) there is a a lot of memory usage in runtime. This is another problem here.

@akkaya.hu

Thank you very much for taking the time to write up all of these details. As I alluded to above, I do not have a significant amount of experience with memory management in JavaScript or WebGL. If you believe there is a bug in our source code (or we could better optimize CesiumJS), I recommend writing up an issue on our GitHub page. Feel free to use a lot of the information that you provided above.

If you write up an issue, I can ensure that it will be reviewed by the rest of our CesiumJS squad quickly.

-Sam

1 Like