Skip to content

Commit 8ef2d67

Browse files
authored
fix: Fix memory leak after navigation (#2168)
1 parent a1323df commit 8ef2d67

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/preload.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { contextBridge } from 'electron';
1+
import { contextBridge, webFrame } from 'electron';
22

33
import { invoke } from './ipc/renderer';
44
import { JitsiMeetElectron, JitsiMeetElectronAPI } from './jitsi/preload';
@@ -10,7 +10,9 @@ import {
1010
serverInfo,
1111
} from './servers/preload/api';
1212
import { setServerUrl } from './servers/preload/urls';
13-
import { createRendererReduxStore } from './store';
13+
import { createRendererReduxStore, listen } from './store';
14+
import { WEBVIEW_DID_NAVIGATE } from './ui/actions';
15+
import { debounce } from './ui/main/debounce';
1416
import { listenToMessageBoxEvents } from './ui/preload/messageBox';
1517
import { handleTrafficLightsSpacing } from './ui/preload/sidebar';
1618
import { whenReady } from './whenReady';
@@ -48,6 +50,17 @@ const start = async (): Promise<void> => {
4850
return;
4951
}
5052

53+
listen(
54+
WEBVIEW_DID_NAVIGATE,
55+
debounce(() => {
56+
const resources = webFrame.getResourceUsage();
57+
// TODO: make this configurable
58+
if (resources.images.size > 50 * 1024 * 1024) {
59+
webFrame.clearCache();
60+
}
61+
}, 1000 * 30)
62+
);
63+
5164
listenToNotificationsRequests();
5265
listenToScreenSharingRequests();
5366
listenToMessageBoxEvents();

0 commit comments

Comments
 (0)