From 5cc84eae648d2438898ea5d63d393b5ecb018f2c Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 17 Mar 2016 17:36:54 +0100 Subject: [PATCH] Leak: history service (back/forward) navigation is unbounded (fixes #4362) --- src/vs/workbench/services/history/browser/history.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/vs/workbench/services/history/browser/history.ts b/src/vs/workbench/services/history/browser/history.ts index d05a5306d18..979ce5f3d12 100644 --- a/src/vs/workbench/services/history/browser/history.ts +++ b/src/vs/workbench/services/history/browser/history.ts @@ -232,7 +232,11 @@ interface IStackEntry { } export class HistoryService extends BaseHistoryService implements IHistoryService { + public serviceId = IHistoryService; + + private static MAX_HISTORY_ITEMS = 200; + private _stack: IStackEntry[]; private index: number; private blockEditorEvent: boolean; @@ -369,6 +373,14 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic else { this.index++; this.stack.splice(this.index, 0, entry); + + // Check for limit + if (this.stack.length > HistoryService.MAX_HISTORY_ITEMS) { + this.stack.shift(); // remove first + if (this.index > 0) { + this.index--; + } + } } // Take out on dispose