0

I'm using this code to change how items are shown on a TListView at runtime:

// lvContacts: TListView
// cdsContacts: TClientDataSet with two records
// lcfContacts: TLinkListControlToField

lvContacts.Items.BeginUpdate;
dmLocalData.cdsContacts.DisableControls;
try
  lcfContacts.FillExpressions.Clear;
  if MultiDetailsView then
  begin
    lvContacts.ItemAppearance.ItemAppearance := 'MultiDetailItem';
    with lcfContacts.FillExpressions.AddExpression do
    begin
      SourceMemberName := 'PictureData';
      ControlMemberName := 'Bitmap';
    end;
    with lcfContacts.FillExpressions.AddExpression do
    begin
      SourceMemberName := 'Job';
      ControlMemberName := 'Detail';
    end;
    with lcfContacts.FillExpressions.AddExpression do
    begin
      SourceMemberName := 'email';
      ControlMemberName := 'Detail1';
    end;
    with lcfContacts.FillExpressions.AddExpression do
    begin
      SourceMemberName := 'mobilePhone';
      ControlMemberName := 'Detail2';
    end;
    with lcfContacts.FillExpressions.AddExpression do
    begin
      SourceMemberName := 'landLinePhone';
      ControlMemberName := 'Detail3';
    end;
  end else begin
    lvContacts.ItemAppearance.ItemAppearance := 'ImageListItemBottomDetail';
    with lcfContacts.FillExpressions.AddExpression do
    begin
      SourceMemberName := 'PictureData';
      ControlMemberName := 'Bitmap';
    end;
    with lcfContacts.FillExpressions.AddExpression do
    begin
      SourceMemberName := 'Job';
      ControlMemberName := 'Detail';
    end;
  end;
finally
  lvContacts.Items.EndUpdate;
  dmLocalData.cdsContacts.EnableControls;
end;

I monitored my application on an iPhone with Instruments, and I see about 1 gigabyte of leaked TMoveArrayManager instances every time this code is executed. After only a few times, my iPhone runs out of memory and shuts down my application. I tried to find a better way to dispose of and create live bindings at run-time, but couldn't come up with a better solution. Has anyone ever had such a problem with live bindings?

iMan Biglari
  • 4,674
  • 1
  • 38
  • 83
  • Why do you have to create the binding on each refresh of the list? Just create the binding once and just use it – Sir Rufo Jan 11 '15 at 17:52
  • @SirRufo I don't create the binding on each refresh. I have a button which lets the user to change the view at run-time. – iMan Biglari Jan 12 '15 at 04:38
  • It scares me that a list view might consume gigabytes of memory. And on a mobile platform. Have you got the right tool for the job? – David Heffernan Jan 12 '15 at 08:58
  • @DavidHeffernan My client dataset has two records, each containing a few text records (20-25 characters at max) and a bitmap (about 300-400 kb at most). But, when the above code is executed, Instruments detects memory leaks amounting to 1.5 gigabyte before my app is shutdown. – iMan Biglari Jan 12 '15 at 10:05

0 Answers0