occt-import-js icon indicating copy to clipboard operation
occt-import-js copied to clipboard

GC not working

Open sookie928 opened this issue 1 year ago • 1 comments

Hello! I'm currently running this library in a Node.js environment. However, when I execute the ReadStepFile function as per the example provided, it works fine, but the memory used while running the function does not get collected by the garbage collector and continues to accumulate. Is there a way to resolve this issue? Below is the code I've written

const occtimportjs = require('occt-import-js')();
import fetch from 'node-fetch';

export const loadGeometry = async (url: string): Promise<any> => {
  let occt;
  let fileBuffer;
  try {
    occt = await occtimportjs;
    const response = await fetch(url);

    const buffer = await response.arrayBuffer();

    fileBuffer = new Uint8Array(buffer);

    const result = occt.ReadStepFile(fileBuffer, null);

    return result;
  } catch (error) {
    console.error(error);
    throw new Error('Loading geometry error');
  } finally {
    occt = null;
    fileBuffer = null;
  }
};

sookie928 avatar Oct 16 '23 05:10 sookie928

It seems that attaching event listeners to the process might prevent the Garbage Collector from working as expected since they can create references to the events. Modifications may be needed for the following code

process.on('uncaughtException', function (ex) {
  if (!(ex instanceof ExitStatus)) {
    throw ex;
  }
});

process.on('unhandledRejection', function (reason) {
  throw reason;
});

sookie928 avatar Oct 16 '23 11:10 sookie928