dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]question about Finalize in C#


From: BioChem333
Subject: Re: [DotGNU]question about Finalize in C#
Date: 04 Sep 2002 18:02:00 -0400

Hi,

        The only time you really want to use finalizers (because using them
gives a performance hit) is when you're wrapping native objects that
need to be free()d when you're done using them. Objects with finalizers
(destructors) are handled separately from regular gc'd objects, so their
cleanup isn't synched with the cleanup of other objects; this usually
isn't really important because an object can only be finalized when it
becomes unreachable. For files, you should always close them before
reopening them, so finalizers are the wrong way to go.


Rich



On Wed, 2002-09-04 at 15:59, Ian Fung wrote:
> i asked this in the chan but no one was around. this isnt about developing
> pnet or anything, but i ifigured someone would know the answer to this here
> =).
> 
> 
> C# Q: I understand what Finalize does. but from what i understand, it
>          is not guarentteed to be called (ie only when the GC is called) and
>          it also takes two calls to teh GC to retrieve the object. what kind
>         of cleanup would you want to put in Finalize? i mean for example, if
>           i open a file, wouldnt i want to close it outside of Finalize to
>           make sure it closes everytime instead of putting it in Finalize?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]