473,624 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Debugging code being run during garbage collection?

What's the best way to debug code that is being run during garbage
collection?

We are getting AccessViolation Exceptions that seem to be happening
during garbage collection. But when it hits the debugger, it is at whatever
line of code the main thread was at when the garbage collector decided to
run. In other words, the debugger is in irrelevant code.

In general, if you have bugs in Dispose or finalization methods, what's the
best way to debug such?
Apr 10 '08 #1
8 2144
Well, GC doesn't run Dispose(); only finalize.

And you shouldn't be touching any other objects except "this" in a
finalizer; the idea is to release unmanaged resources, such as Win32
handles that only exist as an int/IntPtr/etc.

You shouldn't touch any other object in a finalizer; it might not really
be there...

Marc
Apr 10 '08 #2

"Marc Gravell" <ma**********@g mail.comwrote in message
news:O0******** ******@TK2MSFTN GP03.phx.gbl...
Well, GC doesn't run Dispose(); only finalize.

And you shouldn't be touching any other objects except "this" in a
finalizer; the idea is to release unmanaged resources, such as Win32
handles that only exist as an int/IntPtr/etc.

You shouldn't touch any other object in a finalizer; it might not really
be there...

I understand. And actually, I try not to write finalizers at all anyway.
But we use .NET WinForms and embed Office in our app using DSO Framer.
So, we use code that Microsoft has written that has finalizers.

And, yes, it might not really be there. But I added a debug command that
just invokes System.GC.Colle ct. After doing certain things in our app, if
I invoke that command, then I get the AccessViolation Exception. Its
possible
that its a timing thing and it was just a really really "lucky" coincidence.

Any suggestions on how to get an idea of what object's finalizer is causing
that would be GREATLY appreciated.

Brian
Apr 10 '08 #3
"Brian" <Ta************ *****@newsgroup .nospamwrote in message
news:uW******** *****@TK2MSFTNG P06.phx.gbl...
What's the best way to debug code that is being run during garbage
collection?

We are getting AccessViolation Exceptions that seem to be happening
during garbage collection. But when it hits the debugger, it is at
whatever
line of code the main thread was at when the garbage collector decided to
run. In other words, the debugger is in irrelevant code.

In general, if you have bugs in Dispose or finalization methods, what's
the
best way to debug such?


User threads are stopped when the GC kicks-in, it's only when the finalizer
thread runs (after a GC run) that user code can continue to run, this
because finalize methods do run on a separate (the finalizer) thread. The GC
itself will not throw an AV,only the finalize method can possibly throw an
AV exception, this is mostly due to a failure in native interop (COM or
PInvoke) code. The only way to debug such failures is by attaching the
program to a debugger when the failure occurs.

Willy.

Apr 10 '08 #4

"Steven Cheng [MSFT]" <st*****@online .microsoft.comw rote in message
news:rr******** ******@TK2MSFTN GHUB02.phx.gbl. ..
The windbg(debuggin g tools for windows) is a common
debugger for production environment debugging(crash , hang ,high cpu...).
Here is some reference introducing it:

Thanks for those links! They will prove useful, I'm sure.
We did find the problem... and since I suspect others have this problem... I
thought I'd document it here...

Many of the posts on the net about AccessViolation Exceptions have a stack
trace similar to some of ours... coming out of the ToolTip code, which
evidently uses some Unsafe code underneath (based on the naming of their
functions). Given we see the violation show up in a variety of places, we
did not give any significance to any of them. However, it seems that the
ToolTip stuff is the unsafe code that was causing the problem. We removed
it from the panel in question, and the AccessViolation Exception has
vanished.

Searching the net further for that pair shows a LOT of people with
AccessViolation s appearing in that ToolTip code, but seemingly nobody is
putting the blame on that ToolTip code. If anyone does a search on that and
gets this note, my recommendation: try removing the ToolTip code, might fix
the problem.

Hope that helps any others with this problem.
Jun 27 '08 #5
"Brian" <Ta************ *****@newsgroup .nospamwrote in message
news:O$******** ******@TK2MSFTN GP04.phx.gbl...
>
"Steven Cheng [MSFT]" <st*****@online .microsoft.comw rote in message
news:rr******** ******@TK2MSFTN GHUB02.phx.gbl. ..
>The windbg(debuggin g tools for windows) is a common
debugger for production environment debugging(crash , hang ,high cpu...).
Here is some reference introducing it:


Thanks for those links! They will prove useful, I'm sure.
We did find the problem... and since I suspect others have this problem...
I thought I'd document it here...

Many of the posts on the net about AccessViolation Exceptions have a stack
trace similar to some of ours... coming out of the ToolTip code, which
evidently uses some Unsafe code underneath (based on the naming of their
functions). Given we see the violation show up in a variety of places, we
did not give any significance to any of them. However, it seems that the
ToolTip stuff is the unsafe code that was causing the problem. We removed
it from the panel in question, and the AccessViolation Exception has
vanished.

Searching the net further for that pair shows a LOT of people with
AccessViolation s appearing in that ToolTip code, but seemingly nobody is
putting the blame on that ToolTip code. If anyone does a search on that
and gets this note, my recommendation: try removing the ToolTip code,
might fix the problem.

Hope that helps any others with this problem.


This might help you forward, but it's not a fix.
Please post your code, this would be more helpful than simply asking other
to removing this from their application code.
Note that tooltip doesn't use "unsafe" code, it calls into unmanaged code,
but this shouldn't be an issue unless there is a bug in the tooltip managed
code or in the unmanaged code called from tooltip.

Willy.

Jun 27 '08 #6

"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:eD******** ******@TK2MSFTN GP05.phx.gbl...
>
This might help you forward, but it's not a fix.
Please post your code, this would be more helpful than simply asking other
to removing this from their application code.
Note that tooltip doesn't use "unsafe" code, it calls into unmanaged code,
but this shouldn't be an issue unless there is a bug in the tooltip
managed code or in the unmanaged code called from tooltip.

Uhh, I understand. Yes, I am suggesting there is a bug in the ToolTip
code that results in AccessViolation Exceptions under certain conditions.
Its not my code... so I can't fix it... or debug it... or post it.

I have added a work item to our TFS to attempt to create an isolated
example that we can send to Microsoft. But not knowing the conditions
that exercise the bug in the ToolTip code, its a bit hard. Early attempts
have failed. And we have higher priorities at the moment.

However, if you do a search on "AccessViolatio nException ToolTip"
you will find numerous cases. If I remember right, some of those
posted code that may have it isolated. I would suggest examining those;
in fact, that may be easier than trying to isolate it out of our code.
Brian
Jun 27 '08 #7
Hi Brian,

Thanks for your follow-up and sharing the result with us.

Yes, it may required much more to get the detailed root cause or fix it
since the problem may reside deep in the underlying code. Anyway, if you
have simple typical code that can repro it, I recommend you submit the
problem to our feedback site:

http://connect.microsoft.com/feedbac...spx?SiteID=210

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
x.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>Subject: Re: Debugging code being run during garbage collection?
Date: Sat, 12 Apr 2008 08:06:29 -0500
>
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:eD******* *******@TK2MSFT NGP05.phx.gbl.. .
>>
This might help you forward, but it's not a fix.
Please post your code, this would be more helpful than simply asking
other
>to removing this from their application code.
Note that tooltip doesn't use "unsafe" code, it calls into unmanaged
code,
>but this shouldn't be an issue unless there is a bug in the tooltip
managed code or in the unmanaged code called from tooltip.


Uhh, I understand. Yes, I am suggesting there is a bug in the ToolTip
code that results in AccessViolation Exceptions under certain conditions.
Its not my code... so I can't fix it... or debug it... or post it.

I have added a work item to our TFS to attempt to create an isolated
example that we can send to Microsoft. But not knowing the conditions
that exercise the bug in the ToolTip code, its a bit hard. Early attempts
have failed. And we have higher priorities at the moment.

However, if you do a search on "AccessViolatio nException ToolTip"
you will find numerous cases. If I remember right, some of those
posted code that may have it isolated. I would suggest examining those;
in fact, that may be easier than trying to isolate it out of our code.
Brian
Jun 27 '08 #8

"Steven Cheng [MSFT]" <st*****@online .microsoft.comw rote in message
news:5D******** *******@TK2MSFT NGHUB02.phx.gbl ...
>
Thanks for your follow-up and sharing the result with us.

Yes, it may required much more to get the detailed root cause or fix it
since the problem may reside deep in the underlying code. Anyway, if you
have simple typical code that can repro it, I recommend you submit the
problem to our feedback site:

http://connect.microsoft.com/feedbac...spx?SiteID=210

FWIW, we did manage to construct an isolated code project that
reproduces the issue. I looked at that "Connect" feedback site...
not sure where I'd submit something there... but I did submit it
to the support email address for certified partners. They should
get it to the right people.

Brian
Jun 27 '08 #9

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

Similar topics

4
284
by: pantichd | last post by:
<I also posted this on microsoft.public.vsnet.debugging 'cuz I didn't know which was more appropriate or would get quickest response> Hello, Can someone tell me how I can view the contents of a collection when in debug mode? For example, I working with a dataset and when the app stops at a breakpoint
16
6722
by: LP | last post by:
Hi, Considering code below. Will it make GC to actually collect. One application creates new instances of a class from 3rd party assembly in a loop (it has to). That class doesn't have .Dispose or any similar method. I want to make sure GC keeps up with the loop. My reasoning if Thread.Sleep(1000) is called; GC will take priority it do its work, right? GC.Collect(); GC.WaitForPendingFinalizers(); System.Threading.Thread.Sleep(1000);
1
1170
by: Welman Jordan | last post by:
When I debug an asp.net application, which would consume a considerable amount of memory, the application throws "unhandled exception" and delivers a 500 error page to the browser. I find that the memory allocated by that application is unable to reclaim. For example, I create a DataSet object, the application quits with a exception during debugging, the memory the DataSet consumes will not be returned to the system, buried within the...
8
3032
by: mike2036 | last post by:
For some reason it appears that garbage collection is releasing an object that I'm still using. The object is declared in a module and instantiated within a class that is in turn instantiated by the mainline. The class that instantiated the object in question is definitely still in existence at the point garbage collection swoops in and yanks it out from under my processing. Is there a way to ensure an instantiated object cannot be freed...
88
8029
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
4
1692
by: R. MacDonald | last post by:
Hello, all, I have a .NET application (VB) that passes the address of a delegate to unmanaged code in a DLL. The unmanaged code then uses the delegate as a call-back. This seems to work fine, but now I am worried about garbage collection. I am concerned that the location of the delegate might be altered as a result of other (unused) objects being garbage collected. This would probably cause undesirable results when the unmanaged DLL...
5
4772
by: R. MacDonald | last post by:
Hello, all, I am currently working on a .Net (VB) application that invokes routines in unmanaged (Fortran) DLLs. The unmanaged routines then communicate with the .Net application by means of a call-back mechanism. These calls pass a string that contains a "command" and a pointer to a SafeArray that (depending on the command) either receives data from the ..Net application or provides data to the .Net application. This mechanism is...
41
3325
by: jacob navia | last post by:
In the C tutorial for lcc-win32, I have a small chapter about a debugging implementation of malloc. Here is the code, and the explanations that go with it. I would appreciate your feedback both about the code and the associated explanations. ---------------------------------------------------------------------
158
7786
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is discouraged due to some specific reason. If someone can give inputs on the same, it will be of great help. Regards, Pushpa
0
8233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.