Hi, I have an array of PShapes that I'm using to construct a line of data in a graph. I add new line fragments to a linkedlist every time there is new data on each frame. After adding these segments to the list I remove any pshapes from the linkedlist that have gone off the screen since they are no longer needed. This works just fine on a mac, but on windows I can see the memory usage for the application increase until an OutOfMemory exception is thrown. I have been using VisualVM to see where the memory usage is going, but the profiler only shows me what's being used in heap space, which looks totally stable and exactly as it should be. I see the PShape instances being collected by the garbage collector. So, that's fine, but the totally memory usage of the application is still increasing. I'm guessing that this leak is coming from some native function not deallocating memory appropriately, but that is just a guess. Any help would be appreciated. This only happens in Windows (Windows 7 more specifically).
PShape newLineSeg = p.createShape();
newLineSeg.beginShape();
newLineSeg
.stroke(this.colour);
newLineSeg.strokeWeight(3);
newLineSeg.noFill();
newLineSeg.vertex(newFragPosX - drawSpacing, curDrawY);
for (int i = 0; i < numNewData; i++) {
dataPoint = data.get(this.nextValue(data,
this.prevStartPos, dataIndexAddend * i));
curDrawY = (int) (Processing.map(dataPoint,
ScrollingLineGraph.this.vertMin,
ScrollingLineGraph.this.vertMax,
ScrollingLineGraph.this.height, 0.0f));
newLineSeg.vertex(newFragPosX + drawSpacing * i, curDrawY);
}
newLineSeg.endShape();
this.curTotalPoints += numNewData;
int maxDataToDraw = Math.min(
ScrollingLineGraph.this.numDataToDraw,
ScrollingLineGraph.this.width);
if (this.curTotalPoints >= maxDataToDraw) {
Iterator<PShape> i = this.lineFragments.iterator();
PShape s;
while (i.hasNext()) {
s = i.next();
if (this.curTotalPoints - s.getVertexCount() - 1 >= maxDataToDraw) {
i.remove();
this.curTotalPoints -= s.getVertexCount() - 1;
} else {
break;
}
}
}