[Haskell-cafe] number of references to a variable

Andrew Coppin andrewcoppin at btinternet.com
Sat Nov 1 13:56:03 EDT 2008

Jan-Willem Maessen wrote:
> On Nov 1, 2008, at 9:38 AM, Andrew Coppin wrote:
>> Alberto G. Corona wrote:
>>> Is there a way to know the number of memory references for a 
>>> variable?. The runtime must know it but i do not know if this 
>>> available for the program trough any low level trick
>> More precisely, the GC computes it each time it runs. (And only 
>> computes it precisely during a "major" pass, not the more frequent 
>> "minor" passes.)
> Even this isn't quite true for most GC algorithms.  The GC only needs 
> to compute whether there is 0 or >= 1 reference to a given location.  
> If you can see it, the answer is always >=1, so this information is 
> much less useful than you might think!

Quite right.

> Usually the clever thing you want to know is "this is the sole 
> reference to the pointed-to object".

Does GHC have weak references? (I seem to recall it does...)

More information about the Haskell-Cafe mailing list