Problem by eliminating from memory a TObjectList<tlabel></tlabel>
I am with a problem to clean from memory a TObjectList< TLabel>, in specific the ObjectList type TLabel. I created two ObjectList, added an item and tried to clean them from the memory: Code Trecho:
tolRectMenuItemProntuario := TObjectList<TRectangle>.Create; tlLabelDadosPaciente := TObjectList<TLabel>.Create(); tlLabelDadosPaciente.Add(lbTituloConvenio); tolRectMenuItemProntuario.Add(rtMenuItemAnamnese); tolRectMenuItemProntuario:= nil; tolRectMenuItemProntuario.DisposeOf; tlLabelDadosPaciente := nil; tlLabelDadosPaciente.DisposeOf;
However by deleting to try to delete the tlLabelDadosPaciente, the TObjectList< TLabel>, the error system:
"Project AppSIGMedOffLine. exe raised exception class EInvalidPointer with message 'Invalid pointer operation'."
There is some different way to delete a TObjectList< TLabel>, because I am also using both ObjectList, but only the TLabel of error.
You are assigning
nilto the variable before running the
DisposeOf. You would have to do this assignment only after performing the method of memory release. Still, I think you should call the method
.Freeinstead of Dispose. And also when creating
falseas parameter. If you do so,
TObjectListwill not destroy the objects when it destroyed itself. Pass
trueonly if you create the objects in runtime and/or want the list to destroy them.