-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add destroy() methods to classes that need cleanup, address vec…
…3 leaks
- Loading branch information
1 parent
02c9131
commit 273c456
Showing
11 changed files
with
239 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@recast-navigation/core': patch | ||
'@recast-navigation/wasm': patch | ||
--- | ||
|
||
feat: add destroy() methods to classes that need cleanup, address vec3 leaks |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const WARNING_MESSAGE = | ||
'recast-navigation found a recast object that was not cleaned up properly.\n' + | ||
'It was destroyed automatically in this case, but this functionality is not reliable.\n' + | ||
'Make sure to call destroy() once you are done with recast objects.'; | ||
|
||
declare class FinalizationRegistry { | ||
constructor(cleanupCallback: (heldValue: any) => void); | ||
register(target: object, heldValue: any, unregisterToken?: object): void; | ||
unregister(unregisterToken: object): void; | ||
} | ||
|
||
const createNoopFinalizer = () => ({ | ||
register: () => {}, | ||
unregister: () => {}, | ||
}); | ||
|
||
const createFinalizer = () => { | ||
const registry = new FinalizationRegistry((callback: () => void) => { | ||
console.warn(WARNING_MESSAGE); | ||
callback(); | ||
}); | ||
|
||
return { | ||
register: (target: { destroy: () => void }) => { | ||
registry.register(target, () => target.destroy(), target); | ||
}, | ||
unregister: (target: any) => { | ||
registry.unregister(target); | ||
}, | ||
}; | ||
}; | ||
|
||
export const finalizer = globalThis.FinalizationRegistry | ||
? createFinalizer() | ||
: createNoopFinalizer(); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.