Re: Using Dispose for auditing?

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 01/19/05


Date: Wed, 19 Jan 2005 12:20:44 -0600

Marina,
> Objects implement IDisposable, so the garbage collector can call Dispose
> on it before collecting it - to make sure all resources were closed prior
> to collection.
Unfortunately the garbage collector never calls Dispose or use IDisposable!
It will call Object.Finalize if your class overrides it, however making the
GC call Finalize might cause your object to hang around in memory
significantly longer then it should (possibly adding pressure to the GC).

The common practice is to have Finalize & Dispose both call
Dispose(boolean).
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconFinalizeDispose.asp

Otherwise I agree with your statements/questions...

Hope this helps
Jay

"Marina" <someone@nospam.com> wrote in message
news:eES0lsZ$EHA.2572@tk2msftngp13.phx.gbl...
> First of all, I am not clear on how figuring out when classes get garbage
> collected are going to help audit changes to a database? Or are you
> auditing something else? Can you please be clear on this?
>
> Also, just because an object had Dispose called on it does *not* mean it
> is garbage collected. Objects implement IDisposable, so the garbage
> collector can call Dispose on it before collecting it - to make sure all
> resources were closed prior to collection. But calling Dispose does
> nothing to make the GC run. Neither does setting the variable to Nothing,
> or any other thing.
>
> The GC will run when it is deemed necessary by the runtime.
>
> "Jonas" <jonas@no.spam.pl> wrote in message
> news:engKckZ$EHA.1400@TK2MSFTNGP11.phx.gbl...
>> Hi!
>>
>> I'm developing the middletiers of an ASP.NET application in VB.NET. I've
>> got a business logic layer in which I would like to perform auditing to a
>> database. Instead of making an auditing call in every method of my
>> classes, would it be a workable way to implement IDisposable in the base
>> class to all the BLL-classes and then in the Dispose method to do the
>> audit call? Do I then have to make sure that all uses of the BLL-classes
>> end with a call to the Dispose-method or can I count on the garbage
>> collector for this?
>>
>> TIA
>>
>> Jonas
>>
>
>



Relevant Pages

  • Re: SqlConnection.Dispose close connection?
    ... The fact is that the garbage collector in c# is a generational collector. ... But a connection could be kept for longer use of course; ... Dispose calls Close anyway. ... By doing so you ensure that the unmanaged resource (i.e., ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Bitmap constructor throwing System.Exception
    ... If your hope is to prevent the absorption of resources... ... calling Dispose() repeatedly may actually cause more problems if the users ... the virtual nature of memory on the PPC ... >> does not force the garbage collector to spin through unused objects at ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: When should I implement IDispose?
    ... We had in VB6 a class called WaitCursor. ... > the using statement in which dispose would be called automatically. ... > are not collected by the garbage collector. ... When I close the app the Finalize is ...
    (microsoft.public.dotnet.general)
  • Re: Should Dispose be called on DataTable and DataSet objects?
    ... First of all, the garbage ... responsibility to put a call to Dispose in a class ... If the DataTable and DataSet classes do not have any unmanaged resources in them, why do they implement the IDisposable interface? ... The garbage collector will call Dispose on each object it is about to collect if that object implements the IDispose interface, to give it one last chance to clean itself up. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Disposing of Forms.
    ... In any way it isn't error to dispose an object even you have a garbage ... > If I display a form using the ShowDialog method, ... or should this be handled by the garbage collector ...
    (microsoft.public.dotnet.languages.csharp)