HI,
I find the very basic animation below has a memory leak (my pagefile usage
number keeps growing in the Windows XP Windows Task Manager Performance
graph).I don't see this with the "animation_blit_gtk.py" example on:

http://matplotlib.sourceforge.net/examples/index.html

(which I used as a starting point for this). In "animation_blit_gtk.py" the
set_ydata() routine is used to update the line for the animation and this
does not leak. But if you call plot again with the new y_data (instead of
using set_ydata), this leaks too. Anyone have an idea on how to stop the
leak? 

thanks,
john




import gtk, gobject
import matplotlib
matplotlib.use('GTKAgg') 
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
from matplotlib.patches import CirclePolygon

fig = plt.figure(figsize=(10,6))
ax = fig.add_subplot(111, autoscale_on=False )
canvas = fig.canvas

plt.axis([-1, 7, -0.5, 2.2])


def update_line():
    global x, y
    print update_line.cnt
    if update_line.background is None:
        update_line.background = canvas.copy_from_bbox(ax.bbox)
    canvas.restore_region(update_line.background)
    
    x_cir = 1.0 + 0.003*update_line.cnt 
    cir =  CirclePolygon((x_cir, 1), 0.3, animated=True, \
                    resolution=12, lw=2 )
    ax.add_patch(cir)
    ax.draw_artist(cir)
        
    canvas.blit(ax.bbox)
    
    if update_line.direction == 0:
        update_line.cnt += 1
        if update_line.cnt > 500:
            update_line.direction = 1
    else:
        update_line.cnt -= 1
        if update_line.cnt < 100:
            update_line.direction = 0
        
    return True



update_line.cnt = 0
update_line.direction = 0
update_line.background = None

def start_anim(event):
    gobject.idle_add(update_line)
    canvas.mpl_disconnect(start_anim.cid)

start_anim.cid = canvas.mpl_connect('draw_event', start_anim)

plt.show()



------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to