[C++ Builder] Residual Memory after ClearValues

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
macicogna
Newbie
Newbie
Posts: 14
Joined: Thu Jan 11, 2007 12:00 am

[C++ Builder] Residual Memory after ClearValues

Post by macicogna » Thu Mar 24, 2016 1:40 pm

Hello,

Using
TeeChart VCL version 710 with BDS 2006 (C++Builder) and
TeeChart VCL version 8 Build 8.08.80307 with RAD 2009 (C++Builder)

I've noticed an effect that I called "Residual Memory" when using TeeChart with huge series of data.
In my real application, it is normal to open studies with series managing data from 10,000 up to 100,000 points. To be worst, there is a dozen of charts and each one has 3 or 5 different series.

I've created a test application with a simple TChart, a TFastLineSeries and two buttons Fill and Clear with code like that:

Code: Select all

void __fastcall
TFormMain::BtFillClick(TObject *Sender)
{
  Series->Clear();
  for (int i=0; i<100000; i++)
  {
    Series->AddXY(i, rand() % 100,"", clTeeColor);
  }
}
//---------------------------------------------------------------------------
void __fastcall
TFormMain::BtClearClick(TObject *Sender)
{
  Chart->SeriesList->ClearValues();
//  Series->Clear();
//  Chart->FreeAllSeries();
}
//---------------------------------------------------------------------------
Using the Windows Task Manager to monitor the memory (in KBytes) allocated for the test application, I mounted the following table:

Code: Select all

---------------------------------------------

#Points   Initial   After Fill   After Clear

---------------------------------------------
  1,000   1844      1868         1860
                    1860         1860
---------------------------------------------
 10,000    1844      2072         2072
                    2072         2072
---------------------------------------------
100,000   1844      4084         2512
                    4124         2552
                    4124         2552
---------------------------------------------
We can note that there is a residual memory allocation even after the ClearValues() call.

I can reproduce the same behavior with FreeAllSeries(), without repeating the Fill call for a second time.

I hope you have any hint about it, because in my real application it kind of keep consuming memory, even when my users close a huge study and open a small one.

Best,

Marcelo.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: [C++ Builder] Residual Memory after ClearValues

Post by Narcís » Tue Mar 29, 2016 2:22 pm

Hello Marcelo,

Using C++ Builder 10 Seattle and also some earlier versions you can use ReportMemoryLeaksOnShutdown like this:

Code: Select all

int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
	try
	{
		Application->Initialize();
		Application->MainFormOnTaskBar = true;
		Application->CreateForm(__classid(TForm1), &Form1);
		Application->Run();
		ReportMemoryLeaksOnShutdown = true;
	}
Using it in the attached project following your instructions, we don't see any memory leak. Tests we made here free memory correctly. A few bytes take some time to free up but pressing the clear button multiple times it's ok.
Attachments
ResidualMemory.zip
(55.7 KiB) Downloaded 1077 times
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

macicogna
Newbie
Newbie
Posts: 14
Joined: Thu Jan 11, 2007 12:00 am

Re: [C++ Builder] Residual Memory after ClearValues

Post by macicogna » Tue Mar 29, 2016 6:14 pm

Hi Narcís,

Thanks for your prompt reply.

Please, note that my report is not a problem with Memory Leaking.

It seems to me that the ClearValues() does not free all the memory allocated with big FastLine series. Maybe something related with Windows Resources and/or Drawing elements that stays in memory waiting for a new series fill up.

Another strange behavior, apparently, is related with your last affirmation:
... but pressing the clear button multiple times it's ok.
In other words, calling ClearValues() multiple times with a empty series will free memory?

I have another problem/post with C++Builder XE2 (post installation use), so I'll wait your reply and test this case with a more recent version of C++Builder. Sorry about testing it with oldies RAD 2009 and BDS 2006.

Also, just for future reference, note that ReportMemoryLeaksOnShutdown does not work with C++Builder.

They say in the wiki:
Note: ReportMemoryLeaksOnShutdown only works on Delphi applications, it has no effect in C++ applications.
Best,

Marcelo.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: [C++ Builder] Residual Memory after ClearValues

Post by Narcís » Fri Apr 15, 2016 1:42 pm

Hi Marcelo,

Many apologies for the delayed reply.

We have been testing with Process Explorer and not even a single byte is lost. Not even adding one thousand nor one hundred thousand points. Task manager may be providing misleading information here. That's Process Explorer output:
a.png
a.png (33.42 KiB) Viewed 13610 times
Private bytes and working set always have exactly the same initial value when clicking the Clear button.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply