[Vega] Fix charts are leaking memory on each refresh (#147309)

Closes: #146170

**Summary:** 
[Vega] Fix charts are leaking memory on each refresh

**Steps for checking:** 
1. Create a new `Dashboard` with one `Vega Visualization `(or two)
2. Open **Dev tools** -> **Memory** -> **Heap snapshot** -> **Take
snapshot** (execute `Collect Garbage` before)
3. Do refresh `Dashboard` 
4. Execute step 2 and compare snapshots


**Before:**

<img width="767" alt="image"
src="https://user-images.githubusercontent.com/20072247/206700742-4f6cb8ad-5a0f-41a5-8a0a-6f058f43d124.png">
 
**After:**

<img width="765" alt="image"
src="https://user-images.githubusercontent.com/20072247/206700824-9f96e44a-7860-47fa-ba3e-acf9b05b1ae1.png">

Co-authored-by: Yaroslav Kuznietsov <kuznetsov.yaroslav.yk@gmail.com>
This commit is contained in:
Alexey Antonov 2022-12-12 13:21:59 +03:00 committed by GitHub
parent 24e2fcf470
commit df65cd907c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -80,7 +80,7 @@ const serializeColumns = (item: Record<string, unknown>, columns: string[]) => {
};
export class VegaAdapter {
private debugValuesSubject = new ReplaySubject<DebugValues>();
private debugValuesSubject = new ReplaySubject<DebugValues>(1);
private error = new BehaviorSubject<string | undefined>(undefined);
bindInspectValues(debugValues: DebugValues) {

View file

@ -142,6 +142,7 @@ export class VegaBaseView {
this._view.finalize();
}
this._view = null;
this._vegaViewConfig = null;
});
this._vegaViewConfig = this.createViewConfig();
@ -502,6 +503,9 @@ export class VegaBaseView {
// On dispose, clean up, but don't use undefined to prevent repeated debug statements
this._addDestroyHandler(() => {
if (debugObj === window.VEGA_DEBUG) {
window.VEGA_DEBUG.view = null;
window.VEGA_DEBUG.vega_spec = null;
window.VEGA_DEBUG.vegalite_spec = null;
window.VEGA_DEBUG = null;
}
});