If I load some Placemark into the card, I attach events to each event handler. Then you need to clear the map, the user selected a different region. Remove all removeAll objects from the GeoObjectCollection and load the new Placemark .

There is a feeling that the page starts to “swell up” and slow down.

The question is - is it necessary to forcibly disconnect all event handlers before cleaning the collection?

    1 answer 1

    Good day. The Yandex.kart API does not automatically delete event subscriptions. That is, after deleting the entities, the subscriptions will remain in memory.

    This can be corrected only by the explicit deletion of subscriptions. But in order not to keep subscriptions to all objects, you can simplify the code a little.

    1. You can suspend subscriptions directly to the GeoObjectCollection. All standard events will be forwarded.

    2. You can create a group of events through the group () method. https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/reference/IEventManager-docpage/#group

    Like that:

     this._eventsGroup = this._geoObjectCollection.events.group() // Событий геообъектов внутри коллекции будут приходить .add('click', () => { // ... }); // ... this._eventsGroup.removeAll(); this._geoObjectCollection.removeAll(); 
    • Thanks for the answer. Forced clearing of subscriptions directly GeoObjectCollection saved the situation. - Sergey