|
-
May 4th, 2010, 11:07 PM
#1
Thread Starter
Lively Member
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
-
May 4th, 2010, 11:14 PM
#2
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|