Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in MapLoadEvent #13116

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading