Page 1 of 1

Free CustomAxes?

Posted: Sun Apr 06, 2025 8:52 am
by 16582633
Hi,

I create a certain amount of CustomAxes in my TChart, e.g. by using:

Code: Select all

LAxis := TChartAxis.Create(MyChart)
However, it's not clear to me whether I need to destroy (Free) these axes myself or is the parent chart (MyChart) taking care of this?

In my Project Source I have

Code: Select all

ReportMemoryLeaksOnShutdown := true
If I don't explicitely destroy the CustomAxes, no leaks are reported. However, I cannot find anything in the documentation. Can you please advise on the correct approach to remove (destroy) all CustomAxes? Is there something like:

Code: Select all

MyChart.FreeAllCustomAxes
or should it be

Code: Select all

for ii := 0 to MyChart.CustomAxes.Count - 1 do
MyChart.CustomAxes[ii].Free;
Thanks,
Mark

Re: Free CustomAxes?

Posted: Mon Apr 07, 2025 6:21 am
by yeray
Hello Mark,

CustomAxes is a public property in the TCustomAxisPanel (and derived such as TChart) to access the private FCustomAxes : TChartCustomAxes property (TChartCustomAxes, inherits TOwnedCollection).
Indeed, at the TCustomAxisPanel.Destroy destructor method, the CustomAxes are freed:

Code: Select all

Destructor TCustomAxisPanel.Destroy;
Begin
//...
  FCustomAxes.Free;
//...
end;

Re: Free CustomAxes?

Posted: Mon Apr 07, 2025 6:45 am
by 16582633
Clear, thank you! It's a bit counter-intuitive (typically manual creation requires manual destruction in Delphi) so perhaps an idea to add this to the documentation? :D

Re: Free CustomAxes?

Posted: Mon Apr 07, 2025 8:53 am
by yeray
Hello,

Note the CustomAxes (and many other objects) can also be created at design time or at runtime via the editor. So I guess that would be an obstacle to that "manual creation requires manual destruction" rule.
But yes, I'll check if we can add a note somewhere in the docs.