From: Youngsoo Choi Date: Fri, 11 Sep 2020 01:38:21 +0000 (-0700) Subject: [Service] Call global.gc() when terminating a service X-Git-Tag: accepted/tizen/unified/20200923.093723~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F79%2F243879%2F8;p=platform%2Fframework%2Fweb%2Fwrtjs.git [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 --- 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); } }