Skip to content

Instantly share code, notes, and snippets.

@gene-ressler
Created November 22, 2025 05:06
Show Gist options
  • Select an option

  • Save gene-ressler/bf531b0eb28f3b13dd6e9632d4349871 to your computer and use it in GitHub Desktop.

Select an option

Save gene-ressler/bf531b0eb28f3b13dd6e9632d4349871 to your computer and use it in GitHub Desktop.
Update GC cleanup with exclusion list
/**
* Delete any objects tagged for garbage collection.
*/
export const cleanup = (exclude?: Array<Manifold | CrossSection>) => {
const deleteUnlessExcluded = getDeleter(exclude);
for (const obj of memoryRegistry) {
// decompose result is an array of manifolds
if (obj instanceof Array)
for (const elem of obj) deleteUnlessExcluded(elem);
else
deleteUnlessExcluded(obj);
}
memoryRegistry.length = 0;
};
/**
* Return an object deleter that honors an optional exclusion list.
*/
const getDeleter = (exclude?: Array<Manifold | CrossSection>) => {
if (exclude) {
const excludeSet = new Set<Manifold | CrossSection>(exclude);
return (obj: Manifold | CrossSection) => {
if (!excludeSet.has(obj)) obj.delete();
};
}
return (obj: Manifold | CrossSection) => obj.delete();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment