mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 09:14:09 +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 defensePostGrid: DefenseGrid;
|
||||||
|
|
||||||
|
private toDelete = new Set<number>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public worker: WorkerClient,
|
public worker: WorkerClient,
|
||||||
private _config: Config,
|
private _config: Config,
|
||||||
@@ -244,6 +246,9 @@ export class GameView implements GameMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public update(gu: GameUpdateViewData) {
|
public update(gu: GameUpdateViewData) {
|
||||||
|
this.toDelete.forEach((id) => this._units.delete(id));
|
||||||
|
this.toDelete.clear();
|
||||||
|
|
||||||
this.lastUpdate = gu;
|
this.lastUpdate = gu;
|
||||||
|
|
||||||
this.updatedTiles = [];
|
this.updatedTiles = [];
|
||||||
@@ -283,6 +288,10 @@ export class GameView implements GameMap {
|
|||||||
this.defensePostGrid.removeDefense(unit);
|
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