I've been working on a PIXI.js application and I'm faced with the challenge of managing resources to prevent memory leaks. To address this issue, I am utilizing the DisplayObject.destroy
method.
When a display object is destroyed, many of its internal values are set to null
and _destroyed
is flagged as true.
This has become problematic because some parts of the application operate based on events rather than a game loop. Consequently, certain logic attempts to modify display objects and encounters errors due to missing transformations.
If properties of a display object like position and scale were not exposed as unguarded getters, the situation would be different.
get x() {
// An unguarded getter will throw an error if this.position is null!
return this.position.x;
}
In my current Typescript setup, I have extended the display object and adjusted x,y properties as follows:
get x() {
// Since this.position is also a getter, accessing transform first ensures safety
return this.transform && this.position.x;
}
How can this issue be addressed?
And, why is DisplayObject._destroyed
kept private?