Created
November 22, 2025 05:06
-
-
Save gene-ressler/bf531b0eb28f3b13dd6e9632d4349871 to your computer and use it in GitHub Desktop.
Update GC cleanup with exclusion list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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