473,382 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Garbage Collector Reference Counting

Hi all,

I was wondering if there is a way to get the number of references an
objects have (ie, other objects reference that object)? I know
that .Net GC uses a different mechanism than the RefCount in C++
since .Net uses managed objects. I just need to know if there is any
way possible to get this number.

Any comments would be appreciated.
Nov 29 '07 #1
8 1702
Unless you hook into the CLR, the answer is effectively no.

What do you want this information for?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<md****@gmail.comwrote in message
news:6a**********************************@a39g2000 pre.googlegroups.com...
Hi all,

I was wondering if there is a way to get the number of references an
objects have (ie, other objects reference that object)? I know
that .Net GC uses a different mechanism than the RefCount in C++
since .Net uses managed objects. I just need to know if there is any
way possible to get this number.

Any comments would be appreciated.

Nov 29 '07 #2
Many of the debuggers / memory profilers will do it.

The ones that I use that have this feature are:
- Windbg + Son of Strike. I often use the sosex extension as well, as I like
it's commands quite a bit more than SOS's.

- Scitech Memory Profiler will give you this.

- I *think* the RedGate Memory profiler gives you this.

--
Chris Mullins

<md****@gmail.comwrote in message
news:6a**********************************@a39g2000 pre.googlegroups.com...
Hi all,

I was wondering if there is a way to get the number of references an
objects have (ie, other objects reference that object)? I know
that .Net GC uses a different mechanism than the RefCount in C++
since .Net uses managed objects. I just need to know if there is any
way possible to get this number.

Any comments would be appreciated.

Nov 29 '07 #3
I should elaborate, from within your program, you can't, but using
external tools, you can.

Which are you trying to do, get it in your program, or outside of your
program?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:un****************@TK2MSFTNGP05.phx.gbl...
Unless you hook into the CLR, the answer is effectively no.

What do you want this information for?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<md****@gmail.comwrote in message
news:6a**********************************@a39g2000 pre.googlegroups.com...
>Hi all,

I was wondering if there is a way to get the number of references an
objects have (ie, other objects reference that object)? I know
that .Net GC uses a different mechanism than the RefCount in C++
since .Net uses managed objects. I just need to know if there is any
way possible to get this number.

Any comments would be appreciated.


Nov 29 '07 #4
Basically, we are building a WPF application and we are running
through performance issues, mostly memory issues. The problem resides
where objects are not being collected by the GC even after the
application have no use for it. I have tried nulling out the objects
and calling GC.Collect() but it proved futile.

One of the issues we found is with the event subscription bug where
objects that have its event handlers subscribed are not being
collected because the subscriber have a reference to it in some form.
I tried removing the subscription using (-=) operator but it didn't
seem to work.

So I am trying to locate what is referencing the object so I can know
how to remove it. Is there another way for this problem or am I going
on the wrong path?
Nov 29 '07 #5
I just made another post and it didn't seem to have gone through. Here
it goes again.

Basically, we have an application written using WPF/XAML and we are
having issues where objects are not being garbaged collected long
before we stopped using it. We tried specifically nulling it out and
calling GC.Collect(). We also tried to remove any event connections
but that didn't seem to work.

See: http://paulstovell.net/blog/index.ph...memory-issues/
for Events connection bugs.

So we're just trying to come up with ways to fix this issue. We
realized that somehow and somewhere the object we want to removed is
being referenced. We just don't know where. This is where the RefCount
comes in.

Any comments would be appreciated.

Nov 29 '07 #6
Use the SciTech memory profile, it'll make your life easy.

Run your app. Click around. Collect a heap snapshot.

Click around for a while. Collect another heap snapshop.

Compare.

It may take a while, but you'll get it.

If you're really stuck, and have a deadline, I know a guy who may be willing
to help you remotely, after hours, for an hourly fee...

I go through this the hard way (via a crash dump, and Son of Strike) here:
http://www.coversant.net/Default.asp...=88&EntryID=28

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.com/blogs/cmullins

<md****@gmail.comwrote in message
news:61**********************************@e23g2000 prf.googlegroups.com...
Basically, we are building a WPF application and we are running
through performance issues, mostly memory issues. The problem resides
where objects are not being collected by the GC even after the
application have no use for it. I have tried nulling out the objects
and calling GC.Collect() but it proved futile.

One of the issues we found is with the event subscription bug where
objects that have its event handlers subscribed are not being
collected because the subscriber have a reference to it in some form.
I tried removing the subscription using (-=) operator but it didn't
seem to work.

So I am trying to locate what is referencing the object so I can know
how to remove it. Is there another way for this problem or am I going
on the wrong path?

Nov 30 '07 #7
On Thu, 29 Nov 2007 13:59:43 -0800 (PST), "md****@gmail.com"
<md****@gmail.comwrote:
>Hi all,

I was wondering if there is a way to get the number of references an
objects have (ie, other objects reference that object)? I know
that .Net GC uses a different mechanism than the RefCount in C++
since .Net uses managed objects. I just need to know if there is any
way possible to get this number.

Any comments would be appreciated.
As you said, the .NET GC does not actually use reference counting. The
references are established only during the actual garbage collection,
and I don't think they are actually counted even then -- the GC only
needs to know whether there is at least one reference or not, so it
wouldn't make sense to count them and store the count.

You would need an external tool like a profiler that maintains its own
object reference tree.
--
http://www.kynosarges.de
Nov 30 '07 #8
mdoxdo... It seems to me that in .NET most classes that implement the
Observable pattern use "client driven registration" where the Supplier
fires the event, but the Clients register an interest in the event. As a
result you can the see the lapsed listener memory problem.

"The “lapsed listener” problem occurs when objects subscribe to events
and subsequently fall out of scope. The problem is that the event
subscriber doesn’t get garbage collected because the event is still
holding a reference to it inside of the event’s invocation list."

I think it is possible to use "supplier driven registration" in which
the supplier fires event and registers/unregisters listeners. This
requires that each listener implement an interface with GetXXXHandler
methods that return a delegate for each XXXHandler.

Regards,
Jeff
>>See:
http://paulstovell.net/blog/index.ph...s-to-possible-
memory-issues/
for Events connection bugs.<<

*** Sent via Developersdex http://www.developersdex.com ***
Dec 2 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Nick Jacobson | last post by:
In the Python documentation on Extending and Embedding (in section 1.10), there's a quote: "Maybe some day a sufficiently portable automatic garbage collector will be available for C. Until...
3
by: Martin Drautzburg | last post by:
Just for curiosity: does python use a mark-and-sweep garbage collector or simple reference counting? In the latter case it would not garbage collect circular references, right ? For...
2
by: Lasse Skyum | last post by:
Hi folks, I've been wanting to write a garbagecollector for C++ for a little while... my idea is that all objects inherited from "CGCObject" will be garbage-collected if no longer used. So...
4
by: Pedro Miguel Carvalho | last post by:
Greetings. I'm creating a project that as a intricate relation between object kind of like a set where each object in the set can be connect to a subset of object of the set and objects not in...
2
by: Benjamin Johnston | last post by:
Hi, I've found lots of discussion about the JavaScript garbage collector, but no clear answer to this question: Is the garbage collection algorithm used in JavaScript on ASP based on...
13
by: Mingnan G. | last post by:
Hello everyone. I have written a garbage collector for standard C++ application. It has following main features. 1) Deterministic Finalization Providing deterministic finalization, the system...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
46
by: Carlo Milanesi | last post by:
Hello, traditionally, in C++, dynamically allocated memory has been managed explicitly by calling "delete" in the application code. Now, in addition to the standard library strings, containers,...
6
by: Alan Mailer | last post by:
As an ex-VB6 person, I remember often having to make sure that my code set to "Nothing" objects I created throughout my programs. My cursory reading of some VB.Net info is that this may no longer...
3
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.