It really appears to be a known problem.
The source of the problem is the HandleCollector class that is used
internally in Windows.Forms
and maintains list of allocated handles for each type of native handles
(GDIs, Cursors, Windows, HDCs etc).
Each type of handles is also associated with some threshold value. When a
new handle is added,
it checks if the number of allocated handles of that type exceeds the
threshold value, and, if yes,
invokes GC.Collect explicitly.

I don't know wherefrom they invent this resource management strategy, but it
behaves very poor in my case.
The threshold value for HDCs is 4, while in large application like VS.NET it
can easily be about 10-15 HDCs allocated at the same time.
It follows that GC.Collect is invoked very frequently and all modal forms
appear very slowly.

The solution I'm currently trying to use is to set the threshold to
int.MaxValue and thus effectively disable it. This can
be done via Reflection. I found a reference that proposes the similar
approach to the problem:

[1] http://www.alphora.com/tiern.asp?ID=HDCHACK

If someone has better ideas or more information about it, I'll still
appreciate it.

Thanks,
Dmitry

----- Original Message -----
From: "Dmitry Shaporenkov" <[EMAIL PROTECTED]>
To: "Moderated discussion of advanced .NET topics."
<[EMAIL PROTECTED]>
Sent: Friday, April 02, 2004 12:31 PM
Subject: Re: [ADVANCED-DOTNET] GC problem in ShowDialog


> J.,
>
> thanks for this information. It looks very much like the cause of the
> problem.
> I wonder why purely managed applications do not suffer from this issue
> though.
> Of course, I'm using .NET framework 1.1.
>
> As I has already mentioned, my own googling finished with no success just
> like yours.
>
> Any further comments / ideas?
>
> Thanks,
> Dmitry
>
> ----- Original Message -----
> From: "J. Merrill" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, April 01, 2004 3:38 AM
> Subject: Re: [ADVANCED-DOTNET] GC problem in ShowDialog
>
>
> > What version of the framework?  (Likely 1.1 I guess if you're using
VS.NET
> 2003.)
> >
> > I cannot find it now, but I'm rather sure that I saw a reference
somewhere
> on the net to what was described as a bug, that in some circumstance (it
> might have been "in a modal dialog") a GC is triggered every time some
very
> common Windows internal action (a Paint? a Refresh?) occurs.  I had not,
at
> the time, tried to confirm the correctness of the assertion that this bug
at
> some time existed.
> >
> > If there were multiple GCs for each ShowDialog, that would match what
> you're seeing.  A single GC would normally not take much time, even when
> VS.NET is running.
> >
> > I googled without success in locating what I'm sure I saw.  Hopefully
> someone else can say something other than "you must be crazy" <g>.
> >
> > HTH
> >
> > At 05:33 AM 3/31/2004, Dmitry Shaporenkov wrote
> > >Hi,
> > >
> > >in my application (that is indeed an add-in for VS.NET 2003) I observe
a
> > >somewhat odd problem: all modal forms appear on the screen very slowly.
> > >Performance counters say that the garbage collection occurs each time
> > >ShowDialog is called. Frequently, GC in ShowDialog happens even in
older
> > >generations, so each modal form takes several seconds to appear!
> > >Interestingly, when the same forms are shown modeless, GC is not
> triggered.
> > >I reproduced this effect quite stably. Moreover, the effect seems to
bear
> no
> > >relation to the overall memory usage of the VS.NET application that is
> not
> > >very high on small projects (in fact, CLR profiler reports only 8 Mb in
> > >managed heap, and modal forms are still very slow!), and the machine on
> > >which I tested it exhibits 1 Gb RAM.
> > >
> > >So, my question is: what ShowDialog does that triggers GC?
> > >
> > >Googl'ing did not shed light on the issue.
> > >
> > >
> > >Any ideas on the origin of the problem will be greatly appreaciated.
> > >
> > >Thanks in advance,
> > >Dmitry
> >
> >
> > J. Merrill / Analytical Software Corp
> >
> > ===================================
> > This list is hosted by DevelopMentorŪ  http://www.develop.com
> > Some .NET courses you may be interested in:
> >
> > NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
> > http://www.develop.com/courses/gaspdotnetls
> >
> > View archives and manage your subscription(s) at
> http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to