Skip to content

Commit

Permalink
Support to unregister from engine observer (#124)
Browse files Browse the repository at this point in the history
We keep a set of perfetto instances and reuse them, hence
each use needs to cleanup its references, or it is a memory leak.
  • Loading branch information
dfriederich authored Sep 17, 2024
1 parent ddd7bfb commit 47b36da
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ui/src/frontend/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,18 @@ class Globals {
}
}

addEngineReadyObserver(observer: (engine: EngineConfig) => void): void {
this._engineReadyObservers.push(observer);
/** Register an engine ready observer.
*
* returns a cleanup function, to be called to unregister.
*/
addEngineReadyObserver(observer: (engine: EngineConfig) => void): ()=>void {
this._engineReadyObservers.push(observer);
return ()=> {
const index = this._engineReadyObservers.indexOf(observer);
if (index >= 0) {
this._engineReadyObservers.splice(index, 1);
}
};
}

/**
Expand Down

0 comments on commit 47b36da

Please sign in to comment.