I'm trying use client-side feature layer to display tweenty thounds polygon on map, i need add/remove layer frenquenly, i found when a add some layer then remove all of it, chrome memory usage only decrese a small part of it increase.
there is some code of my app:
create map and mapview:
cosnt map = new Map({
basemap: 'osm'
})
const mapView = new MapView({
container: 'viewDiv',
map,
center: [xx, yy],
zoom: 5
})
add layer:
const graphics = _.map(grids, (grid) => ({
geometry: new Polygon({
hasZ: false,
hasM: false,
rings: grid.ring
}),
attributes: {
ObjectID: grid.id
}
}))
const layer = new FeatureLayer({
source: graphics,
fields,
objectIdField: 'ObjectID',
renderer: renderer,
popupTemplate: pTemplate
})
map.add(layer)
clear layer:
map.removeAll()
I found if i not create MapView(only create Map, and add/remove layer on map) it works fine, does it means i miss call some method on MapView to clear?
============== Update =================
i debug use chrome dev tool memory snapshot, i found when i add then remove layer, there a some object left, e.g. 4.9/esri/layers/graphics/data/DefaultSpatialIndex.js file _.featuresById field, the clean method not called.
Wei,
So the question I have if if you need to add and remove layer from your map then why are you using const for that layer? Because even if you remove the layer you can not reassign that layer with new data or set it to null to clear the memory used by that layer.