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

Message ListMessage List     Post MessagePost Message

  possible memory leak in Python addVolBars
Posted by uber goober on Feb-02-2015 04:30
Hello Peter

I am seeing symptoms of a memory leak in addVolBars:

import resource
from FinanceChart import *

index = 0
while index < 10:

    noOfDays = 100

    extraDays = 30

    rantable = RanTable(9, 6, noOfDays + extraDays)

    rantable.setDateCol(0, chartTime(2011, 9, 4), 86400, 1)

    rantable.setHLOCCols(1, 100, -5, 5)

    rantable.setCol(5, 50000000, 250000000)

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

    c = FinanceChart(720)

    c.setData(timeStamps, highData, lowData, openData, closeData, volData, extraDays)
    c.addMainChart(240)

#comment this line to remove possible memory leak symptom
    c.addVolBars(75, 0x99ff99, 0xff9999, 0x808080)

    memory_used_INT = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
    if index == 0:
        baseline_memory_useINT = memory_used_INT
    if memory_used_INT >= baseline_memory_useINT*1.1:
        print('Warning memory use more than 10% above baseline.')
    print ('Memory usage: %s (kb)' % memory_used_INT)
    index += 1

Memory usage: 11300 (kb)
Memory usage: 12356 (kb)
Warning memory use more than 10% above baseline.
Memory usage: 13148 (kb)
Warning memory use more than 10% above baseline.
Memory usage: 14204 (kb)
Warning memory use more than 10% above baseline.
Memory usage: 14996 (kb)
Warning memory use more than 10% above baseline.
Memory usage: 16052 (kb)
Warning memory use more than 10% above baseline.
Memory usage: 16844 (kb)
Warning memory use more than 10% above baseline.
Memory usage: 17636 (kb)
Warning memory use more than 10% above baseline.
Memory usage: 18692 (kb)
Warning memory use more than 10% above baseline.
Memory usage: 19484 (kb)

  Re: possible memory leak in Python addVolBars
Posted by Peter Kwan on Feb-03-2015 00:20
Hi uber,

We are aware that there was a memory leak when using FinanceChart in Python. It was
fixed on an updated release uploaded to our web site on Feb 25, 2014. Are your
"ChartDirector for Python" downloaded after that date? The file that needs to update to fix
the issue is "pychartdir.py".

If you have used some old versions of "ChartDirector for Python" before, but have updated
to the latest version, please make sure the "pychratdir.py" is updated too. (Sometimes the
"pychartdir.py" was copied to various directories, so it may be possible an older version of
"pychartdir.py" was still in the system.)

For the known bug mentioned above, there is leak even without using addVolBars, but the
leak is more serious with addVolBars. This bug mainly affects scripts that generates a lot of
Financial charts in one script instance (probably in a loop). It does not affect scripts that
generate one chart per instance (such as CGI scripts).

I have tested your code on Windows. I found that there is no memory leak if the latest
version of ChartDirector is used, but there is leak if an earlier version of ChartDirector is
used.

(Because the "import resource" does not work on Windows, instead of using "import
resource", I have set to the loop to execute 10000 times, and use the windows task
manager to check memory usage.)

If the above still does not solve the problem, would you mind to inform me which operating
system and Python version you are using?

Regards
Peter Kwan

  Re: possible memory leak in Python addVolBars
Posted by uber goober on Feb-03-2015 11:10
Yes, that does look right Peter. Looks like I had some old versions on the test server. Thanks for the fast response.