ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  about finance memory release problem
Posted by kuli on Dec-18-2012 17:24
Attachments:
Hello,
    I write simple program in python finance.

#! /usr/bin/python

from Tkinter import *
from FinanceChart import *
import random

class App():
    def __init__(self):
        self.root = Tk()
        newBtn = Button(self.root, text='test', command=self.makeimage)
        newBtn.pack(expand=1)

        noOfDays = 100
        self.extraDays = 30
        rantable = RanTable(9, 6, noOfDays + self.extraDays)
        rantable.setDateCol(0, chartTime(2002, 9, 4), 86400, 1)
        rantable.setHLOCCols(1, 100, -5, 5)
        rantable.setCol(5, 50000000, 250000000)

        self.timeStamps = rantable.getCol(0)
        self.highData = rantable.getCol(1)
        self.lowData = rantable.getCol(2)
        self.openData = rantable.getCol(3)
        self.closeData = rantable.getCol(4)
        self.volData = rantable.getCol(5)

    def makeimage(self):
        c = FinanceChart(640)
        c.addTitle("Finance Chart Demonstration")
        c.setData(self.timeStamps, self.highData, self.lowData, self.openData,
self.closeData, self.volData, self.extraDays)
        c.addMainChart(240)
        c.addSimpleMovingAvg(5, 0x663300)
        c.addSimpleMovingAvg(20, 0x9900ff)
        c.addHLOC(0x008000, 0xcc0000)
        c.addBollingerBand(20, 2, 0x9999ff, 0xc06666ff)
        c.addVolBars(75, 0x99ff99, 0xff9999, 0x808080)
        c.addRSI(75, 14, 0x800080, 20, 0xff0000, 0x0000ff)
        c.addMomentum(75, 12, 0x0000ff)

        # Output the chart
        c.makeChart("finance.png")

if __name__ == "__main__":
    a = App()
    a.root.mainloop()

when i run it.In picture-1 systen memory 9.7M.then press test button 10 times later.
In picture-2 system memory 51.9M.Please suggest me how to release memory when i
keep running program(otherwise program will crash).thank you very much.
2012-12-18 __ 05-03-34.png
2012-12-18 __ 05-04-19.png

  Re: about finance memory release problem
Posted by Peter Kwan on Dec-19-2012 01:06
Hi kuli,

I have tested your code using Python 2.5, 2.6 and 2.7. In my case, the memory does not increase indefinitely even I press the button many times.

ChartDirector will release the memory when the chart object "c" is destroyed. Python uses garbage collection to automatically delete variables that are no longer use. See:

http://www.digi.com/wiki/developer/index.php/Python_Garbage_Collection

According to the above page, Python will automatically delete the unneeded variables and reclaim memory when it has accumulated 700 net allocations. If you prefer to reclaim the memory after, you may ask Python to perform garbage collection more often. See:

http://docs.python.org/2/library/gc.html

Hope this can help.

Regards
Peter Kwan