From a7074bcb103eefddf99c5ee94e52a661db318c37 Mon Sep 17 00:00:00 2001 From: Youngsoo Choi Date: Thu, 10 Sep 2020 18:38:21 -0700 Subject: [PATCH] [Service] Call global.gc() when terminating a service This calls global.gc() when a service app is terminated. Approximately, 1 MB memory is saved by this. Also, the main thread is immediately terminated when there's no running worker thread for service app. Together with: https://review.tizen.org/gerrit/243858 Change-Id: Iab70e9aadedb19295a3784fb5cc3dc1300412995 Signed-off-by: Youngsoo Choi --- wrt_app/common/service_manager.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/wrt_app/common/service_manager.ts b/wrt_app/common/service_manager.ts index 6703ff4..9637542 100644 --- a/wrt_app/common/service_manager.ts +++ b/wrt_app/common/service_manager.ts @@ -21,6 +21,14 @@ export function startService(id: string, filename: string) { if (isMainThread) { let startService = __dirname + '/service_runner.js'; workers[id] = new Worker(startService, { workerData: { id: id, filename: filename } }); + workers[id].on('exit', () => { + try { + global.gc(); + console.log(`global.gc() is called by ${id}`); + } catch (e) { + console.log(`${e.name}: ${e.message}`); + } + }); } } } @@ -34,11 +42,16 @@ export function stopService(id: string) { } runner.stop(id); setTimeout(() => process.exit(), 500); -} else { + } else { workers[id].postMessage('stopService'); setTimeout(() => { workers[id].terminate(); delete workers[id]; + let runningServices = Object.keys(workers).length; + console.log('Running services : ' + runningServices); + if (runningServices === 0 && serviceType !== 'UI') { + process.exit(); + } }, 500); } } -- 2.7.4