Forum > General
How to free memory after using dynamic array
Runner28:
I'm using an dynamic array, something like this:
type
TListRec_part = record
Z1,Z2: string[10];
end;
TListRec = record
X1: integer;
X2: string[20];
X3: array of TListRec_part;
end;
var
List_complet: array of TListRec;
When is no need of this structures, I want to free memory.
I was try
SetLength(List_complet,0);
or
List_complet:=nil;
or
SetLength(List_complet[1].X3,0);
but it gives me an error (Externel:SIGSEGV).
How I may free memory used by this structure?
Thx.
Leledumbo:
No need to to any of them to free memory used by dynamic arrays. It's reference counted and will automatically be freed when no longer referenced. Your SIGSEGV problem comes from somewhere else but it could be related to the memory management, but no one can know without you showing a small compilable program that demonstrates the SIGSEGV.
Handoko:
What about TFPObjectList? Will it be removed automatically when the program closed or must I free it manually?
taazz:
--- Quote from: Handoko on July 19, 2015, 04:36:00 pm ---What about TFPObjectList? Will it be removed automatically when the program closed or must I free it manually?
--- End quote ---
To get you started think of it like this, There are no managed data types in pascal except strings, dynamic arrays and COM interfaces. Everything else needs your attention to get and release the memory needed.
howardpc:
In the particular case of TFPObjectList, If you instantiate your objectlist like this, then the objects will be freed by the list:
--- Code: ---...
myObjList:=TFPObjectList.Create(True);
with myObjList do
begin
...
end;
--- End code ---
Navigation
[0] Message Index
[#] Next page