[fpc-pascal] Reference Counting

Werner Van Belle werner at yellowcouch.org
Sat Apr 3 21:01:02 CEST 2010


Hello Dear Freepascal users,

I'm a newbee to object pascal. I did however program in turbo pascal.
The past couple of days I learned that there exist a variety of
classes/object systems in freepascal. Now, I already figured out that
the generic class generators are that what we are looking for, which
means that we will be generating classes.

Now, as far as I understand it, these classes are in a sense 'smart
pointers' (yes, I come from a C++ env), and I found some hints at
various places that automatic reference counting should be available in
object pascal. So I tried a little testprogram to see when the objects
instatiated from a class are disposed off. Below is the little program:

{$mode objfpc}

Type
   TReferenceCount = Class
 Public
   nummerke: Integer;
   Destructor Destroy;
end;

Destructor TReferenceCount.Destroy;
begin
   WriteLn('Deallocation');
end;

var
   Test    : TReferenceCount;
   Pest    : TReferenceCount;
begin
   Test:=TReferenceCount.Create();
   Pest:=Test;
   Test.nummerke:=100;
   WriteLn('Nummerke in test is ', Test.nummerke);
   WriteLn('Nummerke in pest is ', Pest.nummerke);
   Pest.nummerke:=200;
   WriteLn('Nummerke in test is ', Test.nummerke);
   WriteLn('Nummerke in pest is ', Pest.nummerke);
   Test:=nil;
   Pest:=nil;
end.

So, the question now is where I can find documentation on the reference
counting mechanism in freepascal ?

Any help would be appreciated,

Wkr,

-- 
http://werner.yellowcouch.org/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20100403/09d1a4de/attachment.sig>


More information about the fpc-pascal mailing list