The garbage collector uses some way of determining when an object instance's
reference count reaches zero, because that's what makes the object instance a
candidate for collection.
Some research has been done in determining an object instance's reference
count, either on the fly, or by walking the process datastructure and
counting the number of pointers whose value equals the address of the object
in consideration. This task is made easier by reflection, assuming you can
access the address of an object and then the values of all the pointers in
your application.
There is a linear O(N) technique that gives an upper-bound to the object's
reference count by suggesting that since all 32-bit datatypes are memory
aligned, you can simply take the address-range of an object in question (that
is, its starting and ending addresses) and count the number of times any
32-bit aligned value in your process's allocated memory address space,
specifies a value within that object's address range.
For example, object at address range 0xB8000000-0xA0000000, foreach integer
in your process's memory as cast to a big integer array, does it have a value
in the range of the object.
Maybe that helps in some way...
"Bill O" wrote:
Is there a way to determine the number of references to an object? I only
need a reference count.
Thank you,
Bill