myarr : array [0 .. 21] of array [0 .. 21] of TColor;
above is the declaration , after the use i want to destroy the array of array
for a := 0 to 21 do
for b := 0 to 21 do
myarr[a][b].destroy ;
//myarr[a,b].destroy ;
both the code are giving me error ,
E2018 Record, object or class type required (Delphi)
this is actually implemented inside a class , and i want to do this when the object of class is being destroyed
i have implemented this when a mouse click is executed the previous object(which includes this array) must be destroyed and a new object must be created.Practically when this happens the their must be no any extra memory left , but when i check this in my windows task manager for each click another 200 kb is added ,my app will do this for multiple times.
TColoris an integer type, a value type, and is not a class. Accordingly it is does not need to be freed. The definition ofTColorisSo your array is pretty much equivlent, for the purposes of alloction, to
The elements of such an array do not need to be freed. The array itself will be freed automatically, no matter where you declare it (global, local, class member, record member). It is also a value type.
The best clue that you don’t need to free
TColoris that you never created it in the first place. Allocations and deallocations are always paired.As an aside, you should never call
Destroydirectly. You writeDestroyin code only when implemented the overridden destructor for a class, i.e. like this:When you come to destroy an object you should call
Freeon it. Do not callDestroydirectly. Why not? Well,Freeis implemented like this:The
ifstatement means that if you have an object reference that isnil, then it is safe to callFreeon it without fear of an exception being raised.This is important in case an exception is raised in a constructor. When that happens the destructor is called. If the constructor has only partially completed, then some fields will still be
nil. CallingFreeallows us to write clean destructor code. Without this convenience all our destructors would look like this: