reina
asked on
Problem freeing memory
Hello.
I have problems freeing resources on my application. I don't know if I'm
doing the things well, so please tell me where could be my mistake.
I have some pointers (structures) that I store on a Tlist. Some of that
structures have lists that store more pointers.
So I have something like this:
TAAmostra=^TAmostra;
TAmostra = record
NumAmostra:integer;
N:integer;
hora:TDateTime;
ListaPesagens:TList;
...
prod:TPProduto;
...
end;
TPPesagem=^TPesagem;
TPesagem = record
N:integer;
MBRUTA:single;
Tara:single;
MLiquida:single;
VLiquido:single;
end;
In this situation, the structure TAAmostra has a list (ListaPesagens) that
is going to store the TPPesagem structure.
So then I have this list:
listaAmostras:Tlist;
and the variables
amo:TAAmostra;
pes:TPPesagem
I then create a new dynamic variable and place it in the TList:
new(amo);
amo.numamostra:=b;
...
for a:=1 to 5 do
begin
new(pes);
pes.n:=a;
...
end;
amo.listapesagens.add(pes) ;
listaamostras.add(amo);
So, in this way I can easily access the info I want like this:
procedure search(amo:TAAmostra);
var
a:integer;
pes:TPPesagem;
begin
for a:=0 to amo.listapesagens.count-1 do
begin
pes:=amo.listapesagens.ite ms[a];
...
...
end;
end;
So, this is how I manipulate the structures.
To free them I do something like this:
for a:=0 to listaAmostras.count-1 do
begin
amo:=listaAmostras.Items[a ];
for b:=0 to amo.ListaPesagens.count-1 do
begin
pes:=amo.ListaPesagens.ite ms[b];
dispose(pes);
end;
amo.ListaPesagens.Clear;
amo.ListaPesagens.capacity :=0;
dispose(amo);
end;
listaamostras.clear;
listaamostras.capacity:=0;
My problem is this: I have a procedure that "refreshes" the data in the
structures. To do so, I want to free the memory allocated to the TAAmostra
structure and then create a new one with the new values. Well, it seems it
isn't freeing the memory, because if I run that procedure 20 times in a row
I get an EoutofMemory exception. But if I'm freeing the memory and then
allocating space for exactly the same data, the occupied memory should
always be the same!!!
I know this description is a little long, but this is very important. My
deadline is next wednesday and I must have this problem solved. Anyone can
help?
Thanks for your time.
Best Regards
Goncalo Martins
I have problems freeing resources on my application. I don't know if I'm
doing the things well, so please tell me where could be my mistake.
I have some pointers (structures) that I store on a Tlist. Some of that
structures have lists that store more pointers.
So I have something like this:
TAAmostra=^TAmostra;
TAmostra = record
NumAmostra:integer;
N:integer;
hora:TDateTime;
ListaPesagens:TList;
...
prod:TPProduto;
...
end;
TPPesagem=^TPesagem;
TPesagem = record
N:integer;
MBRUTA:single;
Tara:single;
MLiquida:single;
VLiquido:single;
end;
In this situation, the structure TAAmostra has a list (ListaPesagens) that
is going to store the TPPesagem structure.
So then I have this list:
listaAmostras:Tlist;
and the variables
amo:TAAmostra;
pes:TPPesagem
I then create a new dynamic variable and place it in the TList:
new(amo);
amo.numamostra:=b;
...
for a:=1 to 5 do
begin
new(pes);
pes.n:=a;
...
end;
amo.listapesagens.add(pes)
listaamostras.add(amo);
So, in this way I can easily access the info I want like this:
procedure search(amo:TAAmostra);
var
a:integer;
pes:TPPesagem;
begin
for a:=0 to amo.listapesagens.count-1 do
begin
pes:=amo.listapesagens.ite
...
...
end;
end;
So, this is how I manipulate the structures.
To free them I do something like this:
for a:=0 to listaAmostras.count-1 do
begin
amo:=listaAmostras.Items[a
for b:=0 to amo.ListaPesagens.count-1 do
begin
pes:=amo.ListaPesagens.ite
dispose(pes);
end;
amo.ListaPesagens.Clear;
amo.ListaPesagens.capacity
dispose(amo);
end;
listaamostras.clear;
listaamostras.capacity:=0;
My problem is this: I have a procedure that "refreshes" the data in the
structures. To do so, I want to free the memory allocated to the TAAmostra
structure and then create a new one with the new values. Well, it seems it
isn't freeing the memory, because if I run that procedure 20 times in a row
I get an EoutofMemory exception. But if I'm freeing the memory and then
allocating space for exactly the same data, the occupied memory should
always be the same!!!
I know this description is a little long, but this is very important. My
deadline is next wednesday and I must have this problem solved. Anyone can
help?
Thanks for your time.
Best Regards
Goncalo Martins
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I will leave a recommendation in the Cleanup topic area that this question is:
Split Points between ITugay and God_Ares
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Paul (pnh73)
EE Cleanup Volunteer