Garbage Collection

I am running Ants Profiler to do memory testing on our ASP.net application.  The Profiler reveals that 308,313 System.String objects had been allocated and 17,900 are currently still on the heap.  That means to me that .Net has released 290,413 from memory.  Is there anything that I can do to reclaim the that memory or am I at the mercy of .Net's GC

Any help is appreciated



Answer this question

Garbage Collection

  • MyLady

    Vikram,

    Thanks for replying to my post. I've heard that it is best just to let the GC do its job.  The results seemed overwhelming to me,  far as, there are still 17,900 System.String objects still stored in the heap.  Is it uncommon to have .Net leave so many still in memory Should I not be concerned   What are your thoughts

  • WhyNadeem

    You might want to think about Adding a "%time in garbage collection" counter to the System Monitor on your web server and watching this counter while your application is running. If % time in GC is consistently above, say, 2-3%, then you should spend more time investigating GC issues like the one you posted about.

    If your app is spending too much time in GC, you can look at how your app is creating objects and see if you have the opportunity to reuse objects by clearing them out instead of throwing them away and creating new ones. Of course, this doesn't really apply to strings because .NET already uses that strategy for strings internally.

  • JStalnaker

    Hi,

    Its usually recommended to best leave the GC to do its job. You can however force the GC by calling GC.Collect() explicitly in code.

    GC.Collect()

    When to call GC.Collect()
    http://blogs.msdn.com/ricom/archive/2004/11/29/271829.aspx

    The perils of GC.Collect()
    http://blogs.msdn.com/scottholden/archive/2004/12/28/339733.aspx

    Regards,
    Vikram

  • Garbage Collection