correct way to perform garbage collecting

Posted on 2006-03-19
Last Modified: 2010-04-23
I am working on a project which I am trying desperately to optimize its performance.  I want to perform some reading and writing of a lot of data and perform some garbage collecting as the data is processed.  Anything working code will help.  I posted a question which some very good advice was offered, but I can’t seam to get the advice to work correctly.  I believe it is because I don’t quite understand how to make garbage collecting work efficiently.  My question is I want any good source code for using gc.collect properly.  I really want to try to improve a process where I believe garbage collecting may help alleviate some bottlenecks.  

Thanks you’re your time and valuable expertise,
Question by:gr8life
    LVL 44

    Accepted Solution

    if you try to do your own garbage collection, rather than allowing the GC to take place only when really necessary, you will actually get worse performance, rather than better.  

    LVL 17

    Assisted Solution

    As Arthur_Wood said, you're really not going to gain any advantages by doing your own GC'ing.  If anything, you might want to call the GC right after you've just done a Dispose/Dereference of large sets of data and/or forms.  The problem, though, is that by forcing a GC, you're causing extra work for the system, and it can really be a ding in performance.

    Author Comment

    As I stated I am researching as much as I can to optimize some code and I thought this may be a way to speed up the application. However after reading the posts here I see this approach is not the correct method. Thank you for your quick assistance and expertise.  I will research other options.
    Have a great day,
    LVL 44

    Expert Comment

    glad to be of assistance.
     good luck on your search for performance gains.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now