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 when removing map #13110

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
3 changes: 3 additions & 0 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -3037,6 +3037,9 @@ class Style extends Evented {

destroy() {
this._clearWorkerCaches();
this.fragments.forEach(fragment => {
fragment.style._remove();
});
if (this.terrainSetForDrapingOnly()) {
delete this.terrain;
delete this.stylesheet.terrain;
Expand Down
5 changes: 4 additions & 1 deletion src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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, getMapSessionAPI, postPerformanceEvent, postMapLoadEvent, AUTH_ERR_MSG, storeAuthState, removeAuthState} from '../util/mapbox.js';
import {RequestManager, mapSessionAPI, 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 @@ -4012,6 +4012,9 @@ class Map extends Camera {

PerformanceUtils.clearMetrics();
removeAuthState(this.painter.context.gl);

mapSessionAPI.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 @@ -576,6 +576,11 @@ export class MapSessionAPI extends TelemetryEvent {
}
}, customAccessToken);
}

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

export class TurnstileEvent extends TelemetryEvent {
Expand Down Expand Up @@ -660,9 +665,9 @@ export const performanceEvent_: PerformanceEvent = new PerformanceEvent();
// $FlowFixMe[method-unbinding]
export const postPerformanceEvent: (?string, LivePerformanceData) => void = performanceEvent_.postPerformanceEvent.bind(performanceEvent_);

const mapSessionAPI_ = new MapSessionAPI();
export const mapSessionAPI: MapSessionAPI = new MapSessionAPI();
// $FlowFixMe[method-unbinding]
export const getMapSessionAPI: (number, string, ?string, EventCallback) => void = mapSessionAPI_.getSessionAPI.bind(mapSessionAPI_);
export const getMapSessionAPI: (number, string, ?string, EventCallback) => void = mapSessionAPI.getSessionAPI.bind(mapSessionAPI);

const authenticatedMaps = new Set();
export function storeAuthState(gl: WebGL2RenderingContext, state: boolean) {
Expand Down
Loading