From da16653d5592094948691110789cb506ae7731e1 Mon Sep 17 00:00:00 2001 From: Kamil Sienkiewicz <138137613+kamil-sienkiewicz-asi@users.noreply.github.com> Date: Fri, 15 Mar 2024 10:39:36 +0100 Subject: [PATCH] Fix memory leak in MapLoadEvent (#13116) * chore: clean up MapLoadEvent * chore: remove new line * chore: fix signature-verification-failure * chore: add type --- src/ui/map.js | 14 +++++++++++++- src/util/mapbox.js | 9 +++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ui/map.js b/src/ui/map.js index 5dedc0bb661..ee4af8426d3 100755 --- a/src/ui/map.js +++ b/src/ui/map.js @@ -5,7 +5,17 @@ import {asyncAll, extend, bindAll, warnOnce, uniqueId, isSafariWithAntialiasingB import browser from '../util/browser.js'; import * as DOM from '../util/dom.js'; import {getImage, getJSON, ResourceType} from '../util/ajax.js'; -import {RequestManager, mapSessionAPI, getMapSessionAPI, postPerformanceEvent, postMapLoadEvent, AUTH_ERR_MSG, storeAuthState, removeAuthState} from '../util/mapbox.js'; +import { + RequestManager, + mapSessionAPI, + mapLoadEvent, + getMapSessionAPI, + postPerformanceEvent, + postMapLoadEvent, + AUTH_ERR_MSG, + storeAuthState, + removeAuthState +} from '../util/mapbox.js'; import Style from '../style/style.js'; import EvaluationParameters from '../style/evaluation_parameters.js'; import Painter from '../render/painter.js'; @@ -3891,6 +3901,7 @@ class Map extends Camera { } } }); + postMapLoadEvent(this._getMapId(), this._requestManager._skuToken, this._requestManager._customAccessToken, () => {}); } @@ -4014,6 +4025,7 @@ class Map extends Camera { removeAuthState(this.painter.context.gl); mapSessionAPI.remove(); + mapLoadEvent.remove(); this._removed = true; this.fire(new Event('remove')); diff --git a/src/util/mapbox.js b/src/util/mapbox.js index 9c1faf8b9eb..66e6c5cfd65 100644 --- a/src/util/mapbox.js +++ b/src/util/mapbox.js @@ -514,6 +514,11 @@ export class MapLoadEvent extends TelemetryEvent { }, customAccessToken); } + + remove() { + // $FlowFixMe[incompatible-type] + this.errorCb = null; + } } export class MapSessionAPI extends TelemetryEvent { @@ -657,9 +662,9 @@ const turnstileEvent_ = new TurnstileEvent(); // $FlowFixMe[method-unbinding] export const postTurnstileEvent: (tileUrls: Array, customAccessToken?: ?string) => void = turnstileEvent_.postTurnstileEvent.bind(turnstileEvent_); -const mapLoadEvent_ = new MapLoadEvent(); +export const mapLoadEvent: MapLoadEvent = new MapLoadEvent(); // $FlowFixMe[method-unbinding] -export const postMapLoadEvent: (number, string, ?string, EventCallback) => void = mapLoadEvent_.postMapLoadEvent.bind(mapLoadEvent_); +export const postMapLoadEvent: (number, string, ?string, EventCallback) => void = mapLoadEvent.postMapLoadEvent.bind(mapLoadEvent); export const performanceEvent_: PerformanceEvent = new PerformanceEvent(); // $FlowFixMe[method-unbinding]