Skip to content

Commit

Permalink
feat: remove FinalizationRegistry functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-mason committed Sep 26, 2023
1 parent 6723287 commit 257e988
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 64 deletions.
8 changes: 8 additions & 0 deletions .changeset/wild-files-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@recast-navigation/core': minor
'recast-navigation': minor
---

feat: remove FinalizationRegistry functionality

This was added to catch situations where `destroy()` is not called to free memory. It's current implementation isn't ideal and it adds a fair amount of complexity to the library, so it's being removed for now.
4 changes: 0 additions & 4 deletions packages/recast-navigation-core/src/crowd.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { finalizer } from './finalizer';
import type { NavMesh } from './nav-mesh';
import { NavMeshQuery } from './nav-mesh-query';
import { Raw } from './raw';
Expand Down Expand Up @@ -335,8 +334,6 @@ export class Crowd {
this.navMeshQuery = new NavMeshQuery(
new Raw.Module.NavMeshQuery(this.raw.getNavMeshQuery())
);

finalizer.register(this);
}

/**
Expand Down Expand Up @@ -453,7 +450,6 @@ export class Crowd {
}

destroy(): void {
finalizer.unregister(this);
Raw.Detour.freeCrowd(this.raw);
}
}
35 changes: 0 additions & 35 deletions packages/recast-navigation-core/src/finalizer.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/recast-navigation-core/src/nav-mesh-query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { finalizer } from './finalizer';
import { NavMesh } from './nav-mesh';
import { Arrays, Raw } from './raw';
import type R from './raw-module';
Expand Down Expand Up @@ -26,7 +25,6 @@ export class NavMeshQuery {
} else {
this.raw = new Raw.Module.NavMeshQuery();
this.raw.init(value.navMesh.raw, value.maxNodes ?? 2048);
finalizer.register(this);
}

this.defaultFilter = new Raw.Module.dtQueryFilter();
Expand Down Expand Up @@ -264,7 +262,6 @@ export class NavMeshQuery {
* Destroys the NavMeshQuery instance
*/
destroy(): void {
finalizer.unregister(this);
this.raw.destroy();
}
}
18 changes: 0 additions & 18 deletions packages/recast-navigation-core/src/nav-mesh.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DetourMeshTile, DetourOffMeshConnection, DetourPoly } from './detour';
import { finalizer } from './finalizer';
import { Raw } from './raw';
import type R from './raw-module';
import { Vector3, array, vec3 } from './utils';
Expand All @@ -9,8 +8,6 @@ export class NavMeshGetTilesAtResult {

constructor(raw: R.NavMeshGetTilesAtResult) {
this.raw = raw;

finalizer.register(this);
}

tiles(index: number): DetourMeshTile {
Expand All @@ -22,7 +19,6 @@ export class NavMeshGetTilesAtResult {
}

destroy(): void {
finalizer.unregister(this);
Raw.Module.destroy(this.raw);
}
}
Expand All @@ -32,8 +28,6 @@ export class NavMeshRemoveTileResult {

constructor(raw: R.NavMeshRemoveTileResult) {
this.raw = raw;

finalizer.register(this);
}

data(): number[] {
Expand All @@ -45,7 +39,6 @@ export class NavMeshRemoveTileResult {
}

destroy(): void {
finalizer.unregister(this);
Raw.Module.destroy(this.raw);
}
}
Expand All @@ -55,8 +48,6 @@ export class NavMeshCalcTileLocResult {

constructor(raw: R.NavMeshCalcTileLocResult) {
this.raw = raw;

finalizer.register(this);
}

tileX(): number {
Expand All @@ -68,7 +59,6 @@ export class NavMeshCalcTileLocResult {
}

destroy(): void {
finalizer.unregister(this);
Raw.Module.destroy(this.raw);
}
}
Expand All @@ -78,8 +68,6 @@ export class NavMeshGetTileAndPolyByRefResult {

constructor(raw: R.NavMeshGetTileAndPolyByRefResult) {
this.raw = raw;

finalizer.register(this);
}

tile(): DetourMeshTile {
Expand All @@ -95,7 +83,6 @@ export class NavMeshGetTileAndPolyByRefResult {
}

destroy(): void {
finalizer.unregister(this);
Raw.Module.destroy(this.raw);
}
}
Expand All @@ -105,8 +92,6 @@ export class NavMeshStoreTileStateResult {

constructor(raw: R.NavMeshStoreTileStateResult) {
this.raw = raw;

finalizer.register(this);
}

data(): number[] {
Expand All @@ -118,7 +103,6 @@ export class NavMeshStoreTileStateResult {
}

destroy(): void {
finalizer.unregister(this);
Raw.Module.destroy(this.raw);
}
}
Expand Down Expand Up @@ -169,7 +153,6 @@ export class NavMesh {

constructor(raw?: R.NavMesh) {
this.raw = raw ?? new Raw.Module.NavMesh();
finalizer.register(this);
}

/**
Expand Down Expand Up @@ -543,7 +526,6 @@ export class NavMesh {
*/
destroy(): void {
this.raw.destroy();
finalizer.unregister(this);
Raw.Module.destroy(this.raw);
}
}
4 changes: 0 additions & 4 deletions packages/recast-navigation-core/src/tile-cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NavMeshCreateParams } from './detour';
import { finalizer } from './finalizer';
import { NavMesh } from './nav-mesh';
import { Raw } from './raw';
import type R from './raw-module';
Expand Down Expand Up @@ -76,8 +75,6 @@ export class TileCache {

constructor(raw?: R.TileCache) {
this.raw = raw ?? new Raw.Module.TileCache();

finalizer.register(this);
}

/**
Expand Down Expand Up @@ -192,7 +189,6 @@ export class TileCache {
}

destroy(): void {
finalizer.unregister(this);
this.raw.destroy();
}
}
Expand Down

0 comments on commit 257e988

Please sign in to comment.