Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GC not working #34

Open
sookie928 opened this issue Oct 16, 2023 · 1 comment
Open

GC not working #34

sookie928 opened this issue Oct 16, 2023 · 1 comment

Comments

@sookie928
Copy link

sookie928 commented Oct 16, 2023

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
Copy link
Author

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;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant