mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 17:00:16 +00:00
remove old units in GameView to prevent memory leak
This commit is contained in:
@@ -223,6 +223,8 @@ export class GameView implements GameMap {
|
||||
|
||||
private defensePostGrid: DefenseGrid;
|
||||
|
||||
private toDelete = new Set<number>();
|
||||
|
||||
constructor(
|
||||
public worker: WorkerClient,
|
||||
private _config: Config,
|
||||
@@ -244,6 +246,9 @@ export class GameView implements GameMap {
|
||||
}
|
||||
|
||||
public update(gu: GameUpdateViewData) {
|
||||
this.toDelete.forEach((id) => this._units.delete(id));
|
||||
this.toDelete.clear();
|
||||
|
||||
this.lastUpdate = gu;
|
||||
|
||||
this.updatedTiles = [];
|
||||
@@ -283,6 +288,10 @@ export class GameView implements GameMap {
|
||||
this.defensePostGrid.removeDefense(unit);
|
||||
}
|
||||
}
|
||||
if (!unit.isActive()) {
|
||||
// Wait until next tick to delete the unit.
|
||||
this.toDelete.add(unit.id());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user