I think the code is ok...
Thanks to this article the reference count can be inspected.
http://www.yqcomputer.com/
Here is some new code which inspects it.
procedure TForm1.Button1Click(Sender: TObject);
begin
CreateData;
d1 := cardinal(Data); // storing pointer value when it was created
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
DestroyData;
d2 := cardinal(Data); // store pointer value after it was destroyed
end;
// inspect it.
procedure TForm1.Button5Click(Sender: TObject);
var
ReferenceCount : integer;
begin
if d1=d2 then ShowMessage('pointer still the same'); // is it still the
same address
ReferenceCount := integer( pointer( Cardinal(Data.mAddress) - ( 4 +
4 ) )^ );
ShowMessage( 'string reference count: ' + IntToStr(ReferenceCount) );
end;
The message will show zero after destroy data... so I think the reference
count of the string is zero ?
Though this is hard to believe for me because in the past I have had
problems with strings like this ?!
Maybe inspecting like this is flawed ?!
Well, I am keeping my fingers crossed ;)
If I do get problems in the future maybe just using mData.mAddress := '';
will solve it ;)
But then each node will have to be destroyed manually instead of the general
destroy code of the double linked list etc..
Oh well.
Bye,
Skybuck.