Skip to content

Commit

Permalink
enhance: Limit DevToolsManager action buffer depth to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jan 18, 2024
1 parent 8535c6c commit 4e6a39e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/shiny-maps-double.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions packages/core/src/manager/DevtoolsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default class DevToolsManager implements Manager {
protected started = false;
protected actions: [ActionTypes, State<unknown>][] = [];
protected declare controller: Controller;
maxBufferLength = 100;

constructor(
config?: DevToolsConfig,
Expand Down Expand Up @@ -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]);
}
Expand Down

0 comments on commit 4e6a39e

Please sign in to comment.