[Service] Fix memory leak of parentPort 28/264328/1
authorDongHyun Song <dh81.song@samsung.com>
Thu, 16 Sep 2021 05:02:13 +0000 (14:02 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Thu, 16 Sep 2021 05:17:46 +0000 (14:17 +0900)
From an againg test, which repeatedly launch/terminate an empty
service app, we can find that memory size is continuously
increasing.

With checking service_runner.ts line by line, I figure out that
parentPort (MessagePort) is related to memory leak.

parentPort.close() can be effective to make memory usage stable
a little.

Change-Id: Ia5737915507452100e729246e8f658715d603e81
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/service/service_runner.ts

index 63766c7..e712b03 100644 (file)
@@ -142,15 +142,11 @@ function run() {
     writable: false
   });
 
-  // FIXME: this should be 'wrt.tv?.serviceMount(id)' after Tizen 6.5 release
-  (wrt.tv as any)?.serviceMount(id);
-
+  wrt.tv?.serviceMount(id);
   let filename = workerData.filename;
   start(id, filename);
 
-  if (!parentPort)
-    return;
-  parentPort.on('message', (message) => {
+  parentPort?.on('message', (message) => {
     console.debug(`Received message type : ${message.type}`);
     if (message.type === 'wake') {
       app?.onRequest();
@@ -159,7 +155,8 @@ function run() {
       setTimeout(() => {
         XWalkExtension.cleanup();
         parentPort?.postMessage("will-terminate");
-        (wrt.tv as any)?.serviceUmount(id);
+        parentPort?.close();
+        wrt.tv?.serviceUmount(id);
       }, message.delay);
     }
   });