[fpc-devel] Access Violation withnested DLL'scompiledbyFPC(andsomemore info on bug #4538)

Marc Weustink marc.weustink at cuperus.nl
Fri Dec 16 15:14:30 CET 2005


L505 wrote:
>>>In this case, it decrements 1 and increments 1, so we will always end up with a
> 
> very
> 
>>>simple, easy, solvable problem.
>>>
>>>1 - 1 = 0
>>>1 - 1 = 0
>>
>>Nope, since the string was nil, it isn't decremented, so you end up with
>>a refcount of 1
> 
> 
> The string is 1, not nil
> 1 - 1 = 0 from your diagram indicates 1 is the starting refcount, not nil.
> 
> When I responded to your mail, I didn't just mean if the string was nil, or at 1. I
> meant your diagram didn't seem to click in with me when any number was filled in the
> blank. i.e. 1, 2, 3, 4, 5 or any number.
> 
>>From your diagram, I got this:
> 
> String refcount: 2
>  Decrement(string)       (1 - 1 = 1)
>  string -> 'some string'
>  Increment(string)       (1 + 1 = 2)
> We are at 2 again. What was the point of doing it at all?

Ah now I understand your problem, but you miss the point that we are not 
refcounting the variable S, but its contents.

So S points to 'somevalue' and suppose this string has a refcount of 2. 
Calling DecRef(S) will decrement the refcount of the 'somevalue' string.

After we point S to 'some sting', AddRef(S) will set the refcount of 
'some string' to 1.

So we have 2 equations:
'somevalue':  2 - 1 = 1
'somestring': 0 + 1 = 1

You see, we are working with 2 different strings, and not the same.

[snip]

> The other problem I see with Marc's diagram was that somehow you showed the string
> being decremented before anything even happened. 

Ehm.... I didn't draw any diagram, AFAIK you did.

Marc



More information about the fpc-devel mailing list