[fpc-pascal] High() and Low() for empty dynamic arrays

Fred van Stappen fiens at hotmail.com
Sun Feb 9 15:10:38 CET 2014


> Date: Sun, 9 Feb 2014 13:08:16 +0100
> From: freepascal at ypa-software.de
> To: fpc-pascal at lists.freepascal.org
> Subject: Re: [fpc-pascal] High() and Low() for empty dynamic arrays
> 
> Am 09.02.2014 13:05, schrieb Fred van Stappen:
> > if length(MyArray) > 0 then
> >   for x := 0 to high(MyArray) do
> >     MyArray[x].Free;
> > 
> > But, if i use :
> > 
> >  setlength(MyArray, 0) ;
> > 
> > would it do the same job ?
> 
> No. Your array contains only references to the objects. The references
> where deleted, but the objects remain in memory without any destructor call.
> 
> g
> Michael

OK, many thanks Michael.

Hum, i have a dynamic array of threads.

mythread.create has :
FreeOnTerminate := True;  

So, when the thread terminate, it frees the memory too ? (yes/no).
And it explain why i get a crash and error message if i try to do, for dynamic arrays of threads :

 > if length(MyArray) > 0 then
 >   for x := 0 to high(MyArray) do
 >     MyArray[x].Free;

Because the threads are already freed (yes/no) ?

If so, how can i know if      MyArray[x] was already freed ?

When i use:
if assigned(MyArray[x]) then MyArray[x].Free; 

It does not work. 

Many thanks.

Fred
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140209/f5f44999/attachment.html>


More information about the fpc-pascal mailing list