I think the code is ok...
Thanks to this article the reference count can be inspected.
Here is some new code which inspects it.
procedure TForm1.Button1Click(Sender: TObject);
d1 := cardinal(Data); // storing pointer value when it was created
procedure TForm1.Button4Click(Sender: TObject);
d2 := cardinal(Data); // store pointer value after it was destroyed
// inspect it.
procedure TForm1.Button5Click(Sender: TObject);
ReferenceCount : integer;
if d1=d2 then ShowMessage('pointer still the same'); // is it still the
ReferenceCount := integer( pointer( Cardinal(Data.mAddress) - ( 4 +
4 ) )^ );
ShowMessage( 'string reference count: ' + IntToStr(ReferenceCount) );
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..