Results 1 to 2 of 2

Thread: Finalize never firing

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    108

    Finalize never firing

    why does finalize not get fired when i try to destroy a class until the application is exiting. i feel like because these objects were never actually finalized until the program is exiting that its somehow bogging down the operation of my app

    VS 2008

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Finalize never firing

    Finalize is called by the system when it finalises the object, which occurs when the GC reclaims the memory it occupies. Garbage collection happens automatically when the system wants to do it. There are some rare occasions where you need to force it by calling GC.Collect but the vast majority of apps should just let the system handle it.

    What you do need to do is make sure that you call Dispose on all objects that support when you are done with them, and also make sure you remove references to any objects you no longer need. Note that the Finalize method calls the Dispose method, so this ensures that all disposable objects are disposed at some point, but leaving it up to the system to dispose objects is poor practice. As for removing references, this will often happen automatically as local variables lose scope, but it can also mean clearing collections or setting fields to Nothing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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