Problem deleting a TObjectListTLabel from memory

0

I'm having a problem clearing a TObjectList < TLabel & gt ;, in specific ObjectList of type TLabel. I created two ObjectList, added an item and tried to clear them from memory: Code snippet:

  tolRectMenuItemProntuario := TObjectList<TRectangle>.Create;
  tlLabelDadosPaciente := TObjectList<TLabel>.Create();
  tlLabelDadosPaciente.Add(lbTituloConvenio);
  tolRectMenuItemProntuario.Add(rtMenuItemAnamnese);      
  tolRectMenuItemProntuario:= nil;
  tolRectMenuItemProntuario.DisposeOf;
  tlLabelDadosPaciente := nil;
  tlLabelDadosPaciente.DisposeOf;

While deleting try to delete the PatientLabelData, the TObjectList < TLabel>, the system error:

"

"

Is there any way to delete a TObjectList < TLabel>, because I'm using the same way both ObjectList, but only the TLabel of the error.

    
asked by anonymous 24.11.2017 / 13:35

1 answer

0

You are assigning nil to the variable before executing DisposeOf . You would have to do this assignment only after running the method of releasing memory. Still, I think you should call the .Free method instead of Dispose. And also, when creating TObjectList pass false as parameter. If you do this, TObjectList will not destroy the objects when it is destroyed. You can only pass true if you create the objects at runtime and / or want the list to destroy them.

    
21.12.2017 / 01:49