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
nil
to the variable before running theDisposeOf
. You would have to do this assignment only after performing the method of memory release. Still, I think you should call the method.Free
instead of Dispose. And also when creatingTObjectList
passfalse
as parameter. If you do so,TObjectList
will not destroy the objects when it destroyed itself. Passtrue
only if you create the objects in runtime and/or want the list to destroy them.