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

Message ListMessage List     Post MessagePost Message

  Memory leak? ChartDirector 5.1 (Perl Edition)
Posted by William Fergus Martin on May-08-2014 02:21
I am very pleased with ChartDirector. The quality of charts is very impressive and the functionality is brilliant.

However, I have hit a snag with a memory leak running it on perl.

I am using Mac OSX 10.6.8 and I downloaded ChartDirector 5.1 (Perl Edition) from your website about two days ago, so I assume its the latest version.

I have replicated the problem by using one of the examples from the Docs: Finance Chart 1.

Below I have separated out the section which sets up the "data" and put the section which create the chart into a subroutine called make_chart. I then call make_chart from a loop

The amount of memory in use goes up by around 6M every time it calls the make_chart routine.

Any help would be much appreciated.

Regards,

William
---
Here is the test code:

#!/usr/bin/perl

use lib "/sw/lib/perl5/ChartDirector/lib";
use FinanceChart;

# Create a finance chart demo containing 100 days of data
my $noOfDays = 100;

# To compute moving averages starting from the first day, we need to get extra data
# points before the first day
my $extraDays = 30;

# In this exammple, we use a random number generator utility to simulate the data. We
# set up the random table to create 6 cols x (noOfDays + extraDays) rows, using 9 as
# the seed.
my $rantable = new RanTable(9, 6, $noOfDays + $extraDays);

# Set the 1st col to be the timeStamp, starting from Sep 4, 2002, with each row
# representing one day, and counting week days only (jump over Sat and Sun)
$rantable->setDateCol(0, perlchartdir::chartTime(2002, 9, 4), 86400, 1);

# Set the 2nd, 3rd, 4th and 5th columns to be high, low, open and close data. The
# open value starts from 100, and the daily change is random from -5 to 5.
$rantable->setHLOCCols(1, 100, -5, 5);

# Set the 6th column as the vol data from 5 to 25 million
$rantable->setCol(5, 50000000, 250000000);

# Now we read the data from the table into arrays
my $timeStamps = $rantable->getCol(0);
my $highData = $rantable->getCol(1);
my $lowData = $rantable->getCol(2);
my $openData = $rantable->getCol(3);
my $closeData = $rantable->getCol(4);
my $volData = $rantable->getCol(5);

# having set up the data, here is a test loop to create the charts
for (my $j = 1; $j <= 1000; $j++) {

# memory usage goes up about 6M for every call to make_chart
make_chart($timeStamps, $highData, $lowData, $openData, $closeData, $volData);
sleep 1;

}

sub make_chart {

my ($timeStamps, $highData, $lowData, $openData, $closeData, $volData) = @_;

# Create a FinanceChart object of width 640 pixels
my $c = new FinanceChart(640);

# Add a title to the chart
$c->addTitle("Finance Chart Demonstration");

# Set the data into the finance chart object
$c->setData($timeStamps, $highData, $lowData, $openData, $closeData, $volData,
    $extraDays);

# Add the main chart with 240 pixels in height
$c->addMainChart(240);

# Add a 5 period simple moving average to the main chart, using brown color
$c->addSimpleMovingAvg(5, 0x663300);

# Add a 20 period simple moving average to the main chart, using purple color
$c->addSimpleMovingAvg(20, 0x9900ff);

# Add HLOC symbols to the main chart, using green/red for up/down days
$c->addHLOC(0x008000, 0xcc0000);

# Add 20 days bollinger band to the main chart, using light blue (9999ff) as the
# border and semi-transparent blue (c06666ff) as the fill color
$c->addBollingerBand(20, 2, 0x9999ff, 0xc06666ff);

# Add a 75 pixels volume bars sub-chart to the bottom of the main chart, using
# green/red/grey for up/down/flat days
$c->addVolBars(75, 0x99ff99, 0xff9999, 0x808080);

# Append a 14-days RSI indicator chart (75 pixels high) after the main chart. The
# main RSI line is purple (800080). Set threshold region to +/- 20 (that is, RSI = 50
# +/- 25). The upper/lower threshold regions will be filled with red (ff0000)/blue
# (0000ff).
$c->addRSI(75, 14, 0x800080, 20, 0xff0000, 0x0000ff);

# Append a 12-days momentum indicator chart (75 pixels high) using blue (0000ff)
# color.
$c->addMomentum(75, 12, 0x0000ff);

# Output the chart
$c->makeChart("finance.png");

}

---

I tried it in perl5.8.9 and 5.10.0 and same problem.

---

perl -V

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=darwin, osvers=10.0, archname=darwin-thread-multi-2level
    uname='darwin neige.apple.com 10.0 darwin kernel version 10.0.0d8: tue may 5 19:29:59 pdt 2009; root:xnu-1437.2~2release_i386 i386 '
    config_args='-ds -e -Dprefix=/usr -Dccflags=-g  -pipe  -Dldflags= -Dman3ext=3pm -Duseithreads -Duseshrplib -Dinc_version_list=none -Dcc=gcc-4.2'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc-4.2', ccflags ='-arch x86_64 -arch i386 -arch ppc -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -I/usr/local/include',
    optimize='-Os',
    cppflags='-g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='4.2.1 (Apple Inc. build 5646)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc-4.2 -mmacosx-version-min=10.6', ldflags ='-arch x86_64 -arch i386 -arch ppc -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib
    libs=-ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=true, libperl=libperl.dylib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-arch x86_64 -arch i386 -arch ppc -bundle -undefined dynamic_lookup -L/usr/local/lib'


Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
                        PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_ITHREADS
                        USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API
  Locally applied patches:
        /Library/Perl/Updates/<version> comes before system perl directories
        installprivlib and installarchlib points to the Updates directory
  Built under darwin
  Compiled at Jun 24 2009 00:35:28
  %ENV:
    PERL5LIB="/sw/lib/perl5:/sw/lib/perl5/darwin"
  @INC:
    /sw/lib/perl5/5.10.0/darwin-thread-multi-2level
    /sw/lib/perl5/5.10.0
    /sw/lib/perl5/darwin-thread-multi-2level
    /sw/lib/perl5
    /sw/lib/perl5/darwin
    /Library/Perl/Updates/5.10.0/darwin-thread-multi-2level
    /Library/Perl/Updates/5.10.0
    /System/Library/Perl/5.10.0/darwin-thread-multi-2level
    /System/Library/Perl/5.10.0
    /Library/Perl/5.10.0/darwin-thread-multi-2level
    /Library/Perl/5.10.0
    /Network/Library/Perl/5.10.0/darwin-thread-multi-2level
    /Network/Library/Perl/5.10.0
    /Network/Library/Perl
    /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level
    /System/Library/Perl/Extras/5.10.0
    .

  Re: Memory leak? ChartDirector 5.1 (Perl Edition)
Posted by Peter Kwan on May-09-2014 01:32
Hi William,

Sorry for this problem. This is a known issue. We thought it had already been fixed in the
latest version of ChartDirector for Perl. I have just double checked and found that to my
surprise, we had not included the fix in the Mac OS X and Solaris edition of ChartDirector for
Perl.

I have immediately updated the Mac OS X and Solaris releases to incorporate the fix. Please
kindly download the "ChartDirector for Perl for Mac OS X" once more, and use the updated
"perlchartdir.pm" to replace you existing "perlcahrtdir.pm". This should solve the problem.

Regards
Peter Kwan

  Re: Memory leak? ChartDirector 5.1 (Perl Edition)
Posted by mikeyork on May-15-2014 03:30
I'm having a similar problem with VC++/MFC. Do I need to download a new version too?

  Re: Memory leak? ChartDirector 5.1 (Perl Edition)
Posted by mikeyork on May-15-2014 04:27
Sorry. My bad! I found the memory leak in my own code constructing the Chart.