From 3acb3bb48ceae1c679c17f6ec56492af939c8f74 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 18 May 2021 11:06:48 +0200 Subject: [PATCH] fix memory leak when switching room ids --- src/domain/session/RoomViewModelObservable.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/domain/session/RoomViewModelObservable.js b/src/domain/session/RoomViewModelObservable.js index 9252ee81..8a8254e7 100644 --- a/src/domain/session/RoomViewModelObservable.js +++ b/src/domain/session/RoomViewModelObservable.js @@ -36,6 +36,7 @@ This is also why there is an explicit initialize method, see comment there. export class RoomViewModelObservable extends ObservableValue { constructor(sessionViewModel, roomId) { super(null); + this._statusSubscription = null; this._sessionViewModel = sessionViewModel; this.id = roomId; } @@ -48,9 +49,9 @@ export class RoomViewModelObservable extends ObservableValue { */ async initialize() { const {session} = this._sessionViewModel._sessionContainer; - this._statusObservable = await session.observeRoomStatus(this.id); - this.set(await this._statusToViewModel(this._statusObservable.get())); - this._statusObservable.subscribe(async status => { + const statusObservable = await session.observeRoomStatus(this.id); + this.set(await this._statusToViewModel(statusObservable.get())); + this._statusSubscription = statusObservable.subscribe(async status => { // first dispose existing VM, if any this.get()?.dispose(); this.set(await this._statusToViewModel(status));