Fixes a memory leak where each spines' path was a view of the spine path of the previous run.
The following code (simplified to its essence from an example by Caleb Constantine) leaks memory very slowly -- detectable only using valgrind. It turns out that if the axes are cleared and reused rather than deleted, each spine's path is created as a view based on the spine's path in the previous draw. This creates a long reference chain rather than freeing the previous draw's path view.
This pull request fixes the leak, but @astraw may want to have a look at the fix... I'm not entirely sure why the copy is needed at all -- it hasn't actually been creating a copy all this time any way. Perhaps an alternative solution is just to remove the copy and the assignment (marked with the comment "# replace") altogether?
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
figure = Figure(dpi=None)
canvas = FigureCanvas(figure)
axes = figure.add_subplot(1,1,1)
def draw(channel, seconds):
channel = numpy.sin(numpy.arange(1000))
seconds = numpy.arange(len(channel))
for i in range(10):
Fixes a memory leak where each spines' path was a view of the spine p…
…ath of the previous run.
Remove the copy altogether. Testing reveals that it isn't necessary.
Merged pull request #89 from mdboom/spines_memory_leak.
Fixes a memory leak where each spines' path was a view of the spine path