469,623 Members | 1,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Reference count?

I'm wondering if a tool exists that will integrate with the VS 2005
debugger, such that when I set a breakpoint I can inspect a reference and
see how many other references exist to that object. I'm sure there is an
internal reference count somewhere but have no idea how to inspect it.


May 4 '06 #1
7 2215
Hi Fred,

I am not sure if such reference count exists for managed object as it did
exist for COM objects. Reference count is not needed for garbage collection;
instead, there is a list of allocated objects and the garbage collector
knows the object roots of your app and traverses them and its referenced
objects; when finished, the objects in the list that have not been reached
are considered dead and its memory subject to be reclaimed.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com

"Fred Hedges" <do******@spammuch.com> escribió en el mensaje
news:e3*******************@news.demon.co.uk...
I'm wondering if a tool exists that will integrate with the VS 2005
debugger, such that when I set a breakpoint I can inspect a reference and
see how many other references exist to that object. I'm sure there is an
internal reference count somewhere but have no idea how to inspect it.

May 4 '06 #2
CMM
There is absolutely no reference counting in .NET AFAIK. None! Reference
counting is the source of lots of problems (circular references, leaks,
performance, etc).

When the garbage collector kicks in, it does all sorts of magic, suspends
everything for a brief second, counts references for "newly" created objects
(because "New" objects are typically only needed briefly) and destroys them,
and puts older objects (that have survived for a while) for cleanup later
on.... all designed to lessen the impact of the garbage collection
performance hit. There may be ways to tell where a "dead" object lays in the
line to oblivion... but I don't know how. Perhaps using some of .NET
Diagnostics counters, WMI, or stuff like that.

--
-C. Moya
www.cmoya.com
"Fred Hedges" <do******@spammuch.com> wrote in message
news:e3*******************@news.demon.co.uk...
I'm wondering if a tool exists that will integrate with the VS 2005
debugger, such that when I set a breakpoint I can inspect a reference and
see how many other references exist to that object. I'm sure there is an
internal reference count somewhere but have no idea how to inspect it.

May 4 '06 #3
Just to verify the thoughts of previous posters: There is no reference
count in .NET. The heap doesn't work that way in .NET.

Fred Hedges wrote:
I'm wondering if a tool exists that will integrate with the VS 2005
debugger, such that when I set a breakpoint I can inspect a reference and
see how many other references exist to that object. I'm sure there is an
internal reference count somewhere but have no idea how to inspect it.

May 4 '06 #4

Hmmmmm. I've firmly removed my COM hat now. Thanks for the responses.

So the Garbage Collector can walk the reference list and see if anything in
that list is pointing to something in it's set of allocated "things". Now,
I wonder.... is it possible to find out which things are pointing to a
particular interesting thing, if you see what I mean? ;).

"Göran Andersson" <gu***@guffa.com> wrote in message
news:e7**************@TK2MSFTNGP03.phx.gbl...
Just to verify the thoughts of previous posters: There is no reference
count in .NET. The heap doesn't work that way in .NET.

Fred Hedges wrote:
I'm wondering if a tool exists that will integrate with the VS 2005
debugger, such that when I set a breakpoint I can inspect a reference and
see how many other references exist to that object. I'm sure there is an
internal reference count somewhere but have no idea how to inspect it.

May 4 '06 #5
Hi Fred,

See if there is something like that in the Compuware DevPartner product:

http://www.compuware.com/products/de...5_ENG_HTML.htm

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
"Fred Hedges" <do******@spammuch.com> escribió en el mensaje
news:e3*******************@news.demon.co.uk...

Hmmmmm. I've firmly removed my COM hat now. Thanks for the responses.

So the Garbage Collector can walk the reference list and see if anything
in that list is pointing to something in it's set of allocated "things".
Now, I wonder.... is it possible to find out which things are pointing to
a particular interesting thing, if you see what I mean? ;).


May 4 '06 #6
>So the Garbage Collector can walk the reference list and see if anything in
that list is pointing to something in it's set of allocated "things". Now,
I wonder.... is it possible to find out which things are pointing to a
particular interesting thing, if you see what I mean? ;).


I believe you can do that with the Sos.dll debugger extensions.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 4 '06 #7
Not feasible in any garbage collected system. Note I didn't say not
possible. Its simply that the overhead to do this would be so sever that
the system performance would noticibly suffer.

In VB 6 and COM, the system increments a counter in the object header every
time a reference is added to the object. Then the counter is decremented
whenever a reference is removed. When this counter reaches zero, the object
is removed, decrementing references in any objects it points to.

In .NET the system keeps track of memory roots. These are classically the
program stack and data segment. In .NET, there are additional roots such as
a stack and data segment for each thread in a program as well as other roots
that are maintained by the garbage collector itself. When the GC runs, it
starts with each root and sets a flag that uniquley identifies this GC run.
Any objects that aren't identified on this run are eligible for removal from
memory. After the mark pass, memory is compacted by the GC so that
available memory is consolidated at the end of the heap. Microsoft has a
rather extensive technet article on the .NET garbage collector, but this is
the fundamental description of all modern garbage collection systems. Thus,
there is no way to track the number of references to an object. All the
system needs is one reference and it stops looking.

Mike Ober.

"Fred Hedges" <do******@spammuch.com> wrote in message
news:e3*******************@news.demon.co.uk...
I'm wondering if a tool exists that will integrate with the VS 2005
debugger, such that when I set a breakpoint I can inspect a reference and
see how many other references exist to that object. I'm sure there is an
internal reference count somewhere but have no idea how to inspect it.



May 5 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Richard Cavell | last post: by
1 post views Thread by Tony Johansson | last post: by
3 posts views Thread by Poewood | last post: by
3 posts views Thread by BravesCharm | last post: by
5 posts views Thread by raghu | last post: by
1 post views Thread by ank | last post: by
2 posts views Thread by ank | last post: by
1 post views Thread by oec.deepak | last post: by
275 posts views Thread by Astley Le Jasper | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.