.NETGURU
Garbage Collector questions
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.performance.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

news.microsoft.com
Hello everybody,

we have developed a very large remoting application in c#. The GUI has a MDI
using the standard WinForm MDI container. Now what we experience is that
opening a (rich) databound dialog can take between 1 and 15 seconds. First
we couldn't explain this variation in time since the dialog and the
displayed data were the same at each trial.
After profiling the application with CLR-Profiler, Perfmon and GlowCode I
think the reason for the stall during dialog load is the running of the
garbage collector. Each time the dialogs hangs, the garbage collector runs
many times using more than 60% of the applications CPU time. The profiler
tells us that we have 35.000 - 120.000 objects in the heap (most of them in
the generation 2 heap, since we need to cache some datasets on startup).

Now the first question:
Can anybody tell me if there is a suggested maxCount of objects in the
generation 2 heap?

second question:
Is there a possibility to assign more memory to an application? The machine
has over 700 MB RAM but the garbage collector seems to run over and over
again although there are still 300 MB RAM available. I thought the clr only
triggers a gc.collect when there is no more ram ??

third question:
I',m quite sure that the MDI-Container has a bug, because it seems to hold a
handle to a removed ChildForm (The ChildForm and all its objects is never
cleaned up in a GC run, where the ChildForm opened without setting the
parentProperty is cleaned up perfectly). Can anybody confirm this behaviour
and perhaps suggest a workaround?

forth and last question :)
the profiler shows me thousands of objects of the system.reflection
namespace but I don't know where they come from since we don't use
reflection that excessively. Could it be that remoting calls generate those
objects?

kind regards
Michael Küper

Reply to this message...
 
    
Eric Cadwell
I had the same issue with MDI forms. What version of the framework are you
running?
I was compiling/developing in 1.0 and running on 1.0 with limited testing
targeting 1.1.

Here's a patch out that fixed some 'leaks'.
http://support.microsoft.com/default.aspx?scid=kb;en-us;817723

HTH;
Eric Cadwell
http://www.origincontrols.com

Reply to this message...
 
    
Russell Hind
Eric Cadwell wrote:
[Original message clipped]

And I thought the whole point of the GC was to avoid leaks :)
Reply to this message...
 
    
Chris Lyon [MSFT] (VIP)
Russell,

The whole point of the GC is to automate memory management. The hotfix mentioned below is to fix a resource leak (GDI Objects). The GC was never meant to, and should not
be expected to clean up resources or prevent resource leaks.

-Chris

--------------------
[Original message clipped]

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Reply to this message...
 
    
Russell Hind
Hence the :) in my reply!!!

Chris Lyon [MSFT] wrote:

[Original message clipped]

Reply to this message...
 
    
Niall
As a slight aside, there are a few problems with that hotfix and knowledge
base article:

- The hotfix only applies to version 1.0 of the Framework but the bug is
present in version 1.1.

- The fix made in the hotfix for 1.0 should work for 1.1 as well (it only
needs an if statement really!). However the hotfix obviously only acts on
1.0 dlls.

- The code presented in the "more information" section will not solve all
problems with the MenuItem as in some cases, it will not cause the MenuItem
to be removed from the hashtable it is stored in, and hence it will still
leak.

- The leak leaks more than just GDI resources - it leaks the entire MenuItem
object. Presuming you have a click (or some other event) handler (which you
probably do, otherwise what does the menu item do?), then the MenuItem will
cause the object with the handler to leak as well. Considering that most
times, this is a form, it often turns into a major leak.

I hope it is fixed in Framework 2.0 so we can remove the terrible workaround
hacks from our application! :P

Niall

""Chris Lyon [MSFT]"" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

meant to, and should not
[Original message clipped]

originated.
>

Reply to this message...
 
    
Chris Lyon [MSFT] (VIP)
Hi Michael

(answers inline)

[Original message clipped]

No, there's no max count. Generation 2 is unbounded, so it will grow as necessary. How many objects you need in that generation is dependent on your application. What you
want to avoid, are objects promoted to gen 2 that are no longer used. See http://weblogs.asp.net/ricom/archive/2003/12/04/41281.aspx for more information.

[Original message clipped]

The usually GC collects when generation 0 (ideally the size of your L2 cache) is full. It performs another collection if gen 1 is also full, and gen 2 collection as a last resort (your
process has used all its allocated ram). Keep in mind the GC is non-deterministic and may perform collections at other times, especially if the framework is allocating objects.

[Original message clipped]

Are you calling Dispose on the ChildForms when you're done with them?

[Original message clipped]

Yes. As long as you properly dispose of the objects you use, you shouldn't be concerned with what the Framework allocates.

Hope that helps

-Chris
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Reply to this message...
 
    
Joerg Jooss
"Chris Lyon [MSFT]" wrote:
[...]
[Original message clipped]

That's interesting. Is that a general recommendation or does it only apply
to Windows Forms clients?

Cheers,

--
Joerg Jooss
Click here to reveal e-mail address

Reply to this message...
 
    
Chris Lyon [MSFT] (VIP)
This behaviour is not specific to Winforms, but subject to change in later versions of the runtime. It's just a general heuristic.

-Chris

--------------------
[Original message clipped]

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Reply to this message...
 
    
Joerg Jooss
"Chris Lyon [MSFT]" wrote:
[Original message clipped]

Hm... isn't L2 cache size much too small for any large scale web
application. At least, this value differs *vastly* from what I'd be using on
a JVM, where the "New" generation (i.e. generation 0) is usually one third
of your total managed heap. On a 64 bit JVM with 4 GV heap that's a whopping
1.3 GB...

Cheers,
--
Joerg Jooss
Click here to reveal e-mail address

Reply to this message...
 
    
Harald Ums
[Original message clipped]


The "new space size" depends on the NewRatio which has only the value 2 as
default in the SERVER runtime on sparc.
When you start a client application on intel the default parameters lead to
a new space size of 4 megabytes ...

The new space is NOT identical to generation 0. Since it contains the
"survivor spaces" it is a combination of generation 0 and 1.

Having such a large new size only leads to long pause during garbage
collections.

Reply to this message...
 
    
Joerg Jooss
Harald Ums wrote:
[Original message clipped]

I'll happily clarify that this was based on HP's JVM using the standard JVM
1.3/1.4 generational GC.

[Original message clipped]

Well, and then there's -XX:NewSize and -Xmn, and the various parallel GC
options which change those defaults again ;-)

[Original message clipped]

Yes, but what application server runs with these default settings?

[Original message clipped]

I wouldn't say so. The GC mechanims that apply to generation 1 and survivor
are quite different, and the same is true for their sizing compared to
new/gen 0.

[Original message clipped]

Having a small new size results in too many tenured objects and
OutOfMemoryErrors. In the end, you're trading scavenges for full GCs. It
really depends on your application's profile. For a web application that
imposes an object creation of rate of up to 20 MB/s, a small new size isn't
going to work.

Cheers,
--
Joerg Jooss
Click here to reveal e-mail address

Reply to this message...
 
    
Chris Lyon [MSFT] (VIP)
Hi Joerg

Like I said previously, this is only an initial heuristic the GC uses. Since the .NET GC is self-tuning (I don't know about Java's, so I won't comment on it), the size may change
based on your application's allocation patterns. Also, web servers should be running using Server GC mode, which on a multi-proc machine, creates one GC heap per
processor, essentially multiplying the size of the generations.

-Chris

--------------------
[Original message clipped]

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Reply to this message...
 
    
Henning Krause
Hello,

here we go:
============================================================================
=======================
WebserviceInvokationErrorException.cs:
============================================================================
=======================

public class WebServiceInvokationException: Exception, IEnumerable
{
private NameValueCollection _Details;
private string _Type;
private string _Message;

public string this[string name] { get { return _Details[name]; } }
public string this[int index] {get { return _Details[index]; } }
public string Type { get { return _Type; } }

private WebServiceInvokationException(): base() {}
private WebServiceInvokationException(string message, Exception
innerException): base(message, innerException) {}

public static WebServiceInvokationException UnWrap(SoapException
innerException)
{
NameValueCollection details = new NameValueCollection();
string type;
string message;
WebServiceInvokationException exception;

if (innerException == null) throw new ArgumentException("innerException
must not be null", "innerException");

if (innerException.Detail == null) throw new ArgumentException("Soap
exception does not contain any usable information", "innerException");

message = "";
type = "";
foreach (XmlElement node in innerException.Detail.ChildNodes)
{
if (string.Compare(node.LocalName, "Type", true) == 0) type =
node.InnerText;
else if (string.Compare(node.LocalName, "Message", true) == 0) message =
node.InnerText;
else details.Add(node.LocalName, node.InnerText);
}

exception = new WebServiceInvokationException(message, innerException);
exception._Details = details;
exception._Type = type;

return exception;
}

#region IEnumerable Members

public IEnumerator GetEnumerator()
{
return _Details.GetEnumerator();
}

#endregion

============================================================================
=======================
ServiceBase.cs
============================================================================
=======================

using System;
using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Messaging;
using System.Web.Services.Protocols;
using System.Xml;
using System.Reflection;

using NAW.NoSpamProxy.WebServices;

namespace NAW.NoSpamProxy.WebServices.Implementation
{
/// <summary>
/// Summary description for ServiceBase.
/// </summary>
public abstract class ServiceBase: SoapService
{
private void AddInfo(XmlElement parent, string name, string info)
{
XmlElement node;

node = parent.OwnerDocument.CreateElement(name);
node.AppendChild(parent.OwnerDocument.CreateTextNode(info));
parent.AppendChild(node);
}

public XmlElement WrapException(Exception ex)
{
XmlDocument doc;
XmlElement node;
object value;

doc = new XmlDocument();

// Build the detail element of the SOAP fault.
node = (XmlElement)
doc.CreateElement(SoapException.DetailElementName.Name,
SoapException.DetailElementName.Namespace);

AddInfo(node, "Type", ex.GetType().FullName);

foreach (PropertyInfo info in
ex.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
try
{
value = info.GetValue(ex, null).ToString();
AddInfo(node, info.Name, (value != null) ? value.ToString() : "");
}
catch
{
AddInfo(node, info.Name, "");
}
}
return node;
}
protected override void Receive(SoapEnvelope envelope)
{
try
{
base.Receive(envelope);
}

catch (Exception ex)
{
throw new SoapException(ex.Message, SoapException.ClientFaultCode, "",
WrapException(ex.InnerException));
}
}

}
}

============================================================================
=======================
Each webservice call from the client is wrapped like this:
============================================================================
=======================
try
{
return (ProxyConfiguration)base.SendRequestResponse("MyMethod", new
SoapEnvelope()).GetBodyObject( typeof(MyMethodResponse));
}
catch (SoapException ex)
{
throw WebServiceInvokationException.UnWrap(ex);
}

Greetings,
Henning Krause
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/?page=products" target="_blank">http://www.infinitec.de/?page=products)

"Joerg Jooss" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Henning Krause
Sorry, wrong thread...

--
Henning Krause
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/?page=products" target="_blank">http://www.infinitec.de/?page=products)

"Henning Krause" <Click here to reveal e-mail address> wrote in message
news:O#Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Ravichandran J.V.
"Is there a possibility to assign more memory to an application? The
machine has over 700 MB RAM but the garbage collector seems to run over
and over again although there are still 300 MB RAM available. I thought
the clr only triggers a gc.collect when there is no more ram ??"

Firstly, you need to look into some of the commonly used Garbage
Collector algorithms doing the rounds. The Mono.net (.Net on Linux) uses
the Boehm algorithm; Windows .Net uses the following algorithm (I will
try to summarize it into one line) - When the Generation 0 of the
managed heap is full or nearly full, the GC starts its walk across the
Generations to free memory.

In this process, the first things to be collected are idle and Cache
objects (with lower priority and at times, even high priority cached
items).

Because of this algorithm and the fallout that is caused by promotions
of objects (in an effort to free Generation 0 because Gen. 0 is the
critical memory area for the GC) from gen .0 through 1 to 2, memory is
assumed to be unlimited in .Net as beyond Gen. 2 there is no other area
and this Gen. will just expand as necessary and an OutOfMemoryException
will be thrown if the GC is unable to collect any object from any
generation for a newer object. The Gen. 0 is the place for freshly
created objects.

with regards,

J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply to this message...
 
 
System.ArgumentException
System.Collections.IEnumerable
System.Collections.IEnumerator
System.Collections.Specialized.NameValueCollection
System.OutOfMemoryException
System.Reflection.BindingFlags
System.Reflection.PropertyInfo
System.ServiceProcess.ServiceBase
System.Web.Services.Protocols.SoapException
System.Windows.Forms.MenuItem
System.Xml.XmlDocument
System.Xml.XmlElement




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification