Skip to content

Commit

Permalink
Memory leak fix in sigma.classes.graph
Browse files Browse the repository at this point in the history
The edges referenced in the edges indexes where actually not the ones stored in the sigma.classes.graph instance, but the ones given to it.
Leak found by @sheymann and showed in #340 (thanks!).
  • Loading branch information
jacomyal committed Aug 13, 2014
1 parent 4a019bb commit d821d8c
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/classes/sigma.classes.graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,27 +486,35 @@
this.edgesArray.push(validEdge);
this.edgesIndex[validEdge.id] = validEdge;

if (!this.inNeighborsIndex[edge.target][edge.source])
this.inNeighborsIndex[edge.target][edge.source] = Object.create(null);
this.inNeighborsIndex[edge.target][edge.source][edge.id] = edge;

if (!this.outNeighborsIndex[edge.source][edge.target])
this.outNeighborsIndex[edge.source][edge.target] = Object.create(null);
this.outNeighborsIndex[edge.source][edge.target][edge.id] = edge;

if (!this.allNeighborsIndex[edge.source][edge.target])
this.allNeighborsIndex[edge.source][edge.target] = Object.create(null);
this.allNeighborsIndex[edge.source][edge.target][edge.id] = edge;

if (!this.allNeighborsIndex[edge.target][edge.source])
this.allNeighborsIndex[edge.target][edge.source] = Object.create(null);
this.allNeighborsIndex[edge.target][edge.source][edge.id] = edge;
if (!this.inNeighborsIndex[validEdge.target][validEdge.source])
this.inNeighborsIndex[validEdge.target][validEdge.source] =
Object.create(null);
this.inNeighborsIndex[validEdge.target][validEdge.source][validEdge.id] =
validEdge;

if (!this.outNeighborsIndex[validEdge.source][validEdge.target])
this.outNeighborsIndex[validEdge.source][validEdge.target] =
Object.create(null);
this.outNeighborsIndex[validEdge.source][validEdge.target][validEdge.id] =
validEdge;

if (!this.allNeighborsIndex[validEdge.source][validEdge.target])
this.allNeighborsIndex[validEdge.source][validEdge.target] =
Object.create(null);
this.allNeighborsIndex[validEdge.source][validEdge.target][validEdge.id] =
validEdge;

if (!this.allNeighborsIndex[validEdge.target][validEdge.source])
this.allNeighborsIndex[validEdge.target][validEdge.source] =
Object.create(null);
this.allNeighborsIndex[validEdge.target][validEdge.source][validEdge.id] =
validEdge;

// Keep counts up to date:
this.inNeighborsCount[edge.target]++;
this.outNeighborsCount[edge.source]++;
this.allNeighborsCount[edge.target]++;
this.allNeighborsCount[edge.source]++;
this.inNeighborsCount[validEdge.target]++;
this.outNeighborsCount[validEdge.source]++;
this.allNeighborsCount[validEdge.target]++;
this.allNeighborsCount[validEdge.source]++;

return this;
});
Expand Down

0 comments on commit d821d8c

Please sign in to comment.