Skip to content

Commit

Permalink
Memory leak fixes (RobotWebTools#302)
Browse files Browse the repository at this point in the history
* remove from markers array and dispose children

* refactor repeated code into method
  • Loading branch information
ajspera authored and mvollrath committed Dec 10, 2019
1 parent a4d18ef commit 827b875
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/markers/MarkerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ ROS3D.MarkerClient.prototype.unsubscribe = function(){
ROS3D.MarkerClient.prototype.checkTime = function(name){
var curTime = new Date().getTime();
if (curTime - this.updatedTime[name] > this.lifetime) {
var oldNode = this.markers[name];
oldNode.unsubscribeTf();
this.rootObject.remove(oldNode);
this.removeMarker(name);
this.emit('change');
} else {
var that = this;
Expand All @@ -75,8 +73,8 @@ ROS3D.MarkerClient.prototype.processMessage = function(message){
var oldNode = this.markers[message.ns + message.id];
this.updatedTime[message.ns + message.id] = new Date().getTime();
if (oldNode) {
oldNode.unsubscribeTf();
this.rootObject.remove(oldNode);
this.removeMarker(message.ns + message.id);

} else if (this.lifetime) {
this.checkTime(message.ns + message.id);
}
Expand All @@ -97,3 +95,13 @@ ROS3D.MarkerClient.prototype.processMessage = function(message){

this.emit('change');
};

ROS3D.MarkerClient.prototype.removeMarker = function(key) {
var oldNode = this.markers[key];
oldNode.unsubscribeTf();
this.rootObject.remove(oldNode);
oldNode.children.forEach(child => {
child.dispose();
});
delete(this.markers[key]);
};

0 comments on commit 827b875

Please sign in to comment.