From 4e6a39ea2bfdb1390051f12781e899488609e1a8 Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Thu, 18 Jan 2024 21:15:54 +0000 Subject: [PATCH] enhance: Limit DevToolsManager action buffer depth to 100 --- .changeset/shiny-maps-double.md | 7 +++++++ packages/core/src/manager/DevtoolsManager.ts | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/shiny-maps-double.md diff --git a/.changeset/shiny-maps-double.md b/.changeset/shiny-maps-double.md new file mode 100644 index 000000000000..d16552b5162e --- /dev/null +++ b/.changeset/shiny-maps-double.md @@ -0,0 +1,7 @@ +--- +"@data-client/core": patch +--- + +Limit DevToolsManager action buffer depth to 100 + +This will avoid memory leaks in long running applications, or ones with frequent updates. \ No newline at end of file diff --git a/packages/core/src/manager/DevtoolsManager.ts b/packages/core/src/manager/DevtoolsManager.ts index fc10e55976c1..95f33edeff92 100644 --- a/packages/core/src/manager/DevtoolsManager.ts +++ b/packages/core/src/manager/DevtoolsManager.ts @@ -82,6 +82,7 @@ export default class DevToolsManager implements Manager { protected started = false; protected actions: [ActionTypes, State][] = []; protected declare controller: Controller; + maxBufferLength = 100; constructor( config?: DevToolsConfig, @@ -151,6 +152,10 @@ export default class DevToolsManager implements Manager { if (this.started) { this.devTools.send(action, state, undefined, 'RDC'); } else { + // avoid this getting too big in case this is long running + // we cut in half so we aren't constantly reallocating + if (this.actions.length > this.maxBufferLength) + this.actions = this.actions.slice(this.maxBufferLength / 2); // queue actions this.actions.push([action, state]); }