##
## memleaktest.py
## Login : <gerry@gerry-laptop>
## Started on  Tue Feb 10 10:42:29 2009 gerry
## $Id$
## 
## Copyright (C) 2009 gerry
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
## 
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##


import sys
import os
import shutil

import sqlite3
import dateutil.parser
import dateutil

# whole mess of imports of mpl
import matplotlib
import matplotlib.ticker as ticker
matplotlib.use( 'Agg' ) # png i/o
import matplotlib.pyplot as plt
import numpy.numarray as na
from pylab import *
from matplotlib import mlab
from pylab import figure, show
import time

def memleak1(n):
    l1 = xrange(1000)
    l2 = map(lambda y: y**2, l1)

    for x in xrange(n):
        print "Iteration : " + str(x)
        fig = plt.figure()
        fig.set_figheight(250/fig.get_dpi())
        fig.set_figwidth(1000/fig.get_dpi())
        
        ax = fig.add_subplot(1,1,1)
        ax.set_title ("APBM")
        ax.grid()
        ax.plot(l1,l2)
        fig.savefig("APBM__" + str(x) + ".png", format="png")

        del fig
        del ax



def main():
    memleak1(250)
    print "Sleeping " 
    # when we get to here the memory is freed
    time.sleep (10)

if __name__ == "__main__":
    main()

