Results 1 to 9 of 9

Thread: [2005] Having a question with garbage collection

  1. #1

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    [2005] Having a question with garbage collection

    Bear with my brain fart here, but the garbage collection bit has me a little confused.

    In VB6, in order to free up memory resources
    when I closed a form, I added "set formname = nothing"
    when I closed a recordset I added set "recordsetname = nothing"
    when I closed a connection I added "set conenctionname = nothing"

    Evidently I can't do that anymore? So a program that stays running all day continues to eat up memory until it is all gone?

    Is GC a function of the program (I exit the program and it is called), or is it a funtion of the OS (I exit the program and GC is called at some later time by the OS)?

    I read somewhere that I can call GC at any point in my program, but it exacts a heavy overhead burden, so it is frowned upon.

    I need an "Idiot's guide to garbage collection" explanation from somebody. Thanks in advance.

  2. #2
    Hyperactive Member kayos's Avatar
    Join Date
    Apr 2004
    Location
    Largo, Florida
    Posts
    306

    Re: [2005] Having a question with garbage collection

    GC is how .NET disposes of all your objects.

    now your calls should look like this:
    connection.Dispose() : connection = Nothing

    that calls the GC of .NET to get rid of your object. if you do not dispose it .NET will do it for you when it calls Finalize() to remove unused objects.


    If this post helps, please RATE MY POST!

    Using Visual Studio 2005 SE

  3. #3

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: [2005] Having a question with garbage collection

    When does it call Finalize()?

  4. #4
    Hyperactive Member kayos's Avatar
    Join Date
    Apr 2004
    Location
    Largo, Florida
    Posts
    306

    Re: [2005] Having a question with garbage collection

    there is also a great explination of GC in this free eBook:
    http://msdn.microsoft.com/vbrun/stay...s/introto2005/


    If this post helps, please RATE MY POST!

    Using Visual Studio 2005 SE

  5. #5

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: [2005] Having a question with garbage collection

    I downloaded it. I guess I've got some reading to do.

  6. #6
    Hyperactive Member kayos's Avatar
    Join Date
    Apr 2004
    Location
    Largo, Florida
    Posts
    306

    Re: [2005] Having a question with garbage collection

    Quote Originally Posted by Pasvorto
    When does it call Finalize()?
    Upon some reading (Chapter 1 in that eBook)

    GC will call Finalize() at the end of that objects scope.

    just do a search for "garbage" in chapter 1.


    If this post helps, please RATE MY POST!

    Using Visual Studio 2005 SE

  7. #7

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: [2005] Having a question with garbage collection

    So I really don't have to deal with it.

  8. #8
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: [2005] Having a question with garbage collection

    Well for some things you do, for example with a notifyIcon you have to dispose it as the form is closing because it will remain in the taskbar until you move your mouse over it otherwise. I think I am right about that at least

  9. #9
    Hyperactive Member kayos's Avatar
    Join Date
    Apr 2004
    Location
    Largo, Florida
    Posts
    306

    Re: [2005] Having a question with garbage collection

    Quote Originally Posted by Pasvorto
    So I really don't have to deal with it.
    it is good practice to call Dispose() on objects you will not be using anymore. that book also shows you how to make your own classes disposable by implementing IDisposable.


    If this post helps, please RATE MY POST!

    Using Visual Studio 2005 SE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width