Skip to content

Commit

Permalink
Fix memory leak in MapLoadEvent (#13116)
Browse files Browse the repository at this point in the history
* chore: clean up MapLoadEvent

* chore: remove new line

* chore: fix signature-verification-failure

* chore: add type
  • Loading branch information
kamil-sienkiewicz-asi authored Mar 15, 2024
1 parent 22e183b commit da16653
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -3891,6 +3901,7 @@ class Map extends Camera {
}
}
});

postMapLoadEvent(this._getMapId(), this._requestManager._skuToken, this._requestManager._customAccessToken, () => {});
}

Expand Down Expand Up @@ -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'));
Expand Down
9 changes: 7 additions & 2 deletions src/util/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@ export class MapLoadEvent extends TelemetryEvent {

}, customAccessToken);
}

remove() {
// $FlowFixMe[incompatible-type]
this.errorCb = null;
}
}

export class MapSessionAPI extends TelemetryEvent {
Expand Down Expand Up @@ -657,9 +662,9 @@ const turnstileEvent_ = new TurnstileEvent();
// $FlowFixMe[method-unbinding]
export const postTurnstileEvent: (tileUrls: Array<string>, 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]
Expand Down

0 comments on commit da16653

Please sign in to comment.