Skip to content

Does mouseEvent.localX/localY have un-intended memory leak potential? #770

Open
@SmartArtsStudio

Description

@SmartArtsStudio

mouseEvent.localX/localY are getters which wrap
mouseEvent._get_localX/Y getters which wrap

this.currentTarget.globalToLocal(this.rawX, this.rawY).x;
this.currentTarget.globalToLocal(this.rawX, this.rawY).y;

globalToLocal obviously accepts a 'Point' object via the 'pt' parameter to stem the un-necessary creation of new createjs.Point objects.

p.globalToLocal = function(x, y, pt) {
    return this.getConcatenatedMatrix(this._props.matrix).invert().transformPoint(x,y, pt||new createjs.Point());
};

But the above getters do not pass a 'Point' object into the 'pt' parameter to take advantage of globalToLocal's memory management. Generating a new Point every time mouseEvent.localX/localY are read.

I vaguely recall seeing a comment about Event objects being reused for memory management but didn't fully understand it at the time... is that designed to account for the above situation? If not can I suggest maybe something like a private static class point object be passed into the private getters i.e.

// define MouseEvent static class private property: Point.
MouseEvent._POINT = new createjs.Point;

// new getter / setters:
p._get_localY = function() {
    return this.currentTarget.globalToLocal(this.rawX, this.rawY, MouseEvent._POINT).y;
};

p._get_localX = function() {
    return this.currentTarget.globalToLocal(this.rawX, this.rawY, MouseEvent._POINT).x;
};

Not a big deal in short lived banner ads, but may have some potential to be a problem for input point picking intensive games on a mobile device?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions