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: [xyz, 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.