Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Garbage collection

Reply
Thread Tools

Garbage collection

 
 
luigi
Guest
Posts: n/a
 
      09-17-2006
If i dispose all object in my vb.net c# code what perfomances advantage
i have?

mant thanks

 
Reply With Quote
 
 
 
 
Jon Shemitz
Guest
Posts: n/a
 
      09-17-2006
luigi wrote:

> If i dispose all object in my vb.net c# code what perfomances advantage
> i have?


As written, you get a performance hit, or a negative performance
advantage. Disposing of an object does not reclaim memory, nor does it
hasten garbage collection; writing and calling an empty Dispose method
merely wastes space and time.

Otoh, if you don't really mean "all object[s]" but actually mean "all
objects that implement IDispose" then you are closing resources when
you are done with them, and avoiding "finalization costs."
Finalization is expensive because a dead object must be brought back
to life, promoted to the next generation, and relocated; it then
sticks around, taking up memory, until the next higher-level
collection. So, by calling Dispose on every object that implements it,
you are reducing memory consumption and garbage collection costs.

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn Great reviews & good sales.
 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      09-25-2006
> So, by calling Dispose on every object that implements it,
> you are reducing memory consumption and garbage collection costs.


You mean you are increasing memory consumption and garbage collection costs,
not reducing them.


 
Reply With Quote
 
Jon Shemitz
Guest
Posts: n/a
 
      09-25-2006
"Scott M." wrote:

> > So, by calling Dispose on every object that implements it,
> > you are reducing memory consumption and garbage collection costs.

>
> You mean you are increasing memory consumption and garbage collection costs,
> not reducing them.


No, I meant what I said. Invoking IDispose allows data to be closed
when you're done with, and thus avoids the use of the finalizer. The
finalizer is a fail-safe, but using it adds (avoidable) relocation
costs and means that the gc has to look at the dead object (at least)
twice.

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn Great reviews & good sales.
 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      09-27-2006
Yes, but calling Dispose on every class that exposes it will cause
additional CPU costs, not less.

"Jon Shemitz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Scott M." wrote:
>
>> > So, by calling Dispose on every object that implements it,
>> > you are reducing memory consumption and garbage collection costs.

>>
>> You mean you are increasing memory consumption and garbage collection
>> costs,
>> not reducing them.

>
> No, I meant what I said. Invoking IDispose allows data to be closed
> when you're done with, and thus avoids the use of the finalizer. The
> finalizer is a fail-safe, but using it adds (avoidable) relocation
> costs and means that the gc has to look at the dead object (at least)
> twice.
>
> --
>
> .NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
> Delphi skills make .NET easy to learn Great reviews & good sales.



 
Reply With Quote
 
Jon Shemitz
Guest
Posts: n/a
 
      09-27-2006
"Scott M." wrote:

> Yes, but calling Dispose on every class that exposes it will cause
> additional CPU costs, not less.


No, in most cases it's spending time to save time. When an IDispose
class has a finalizer, its Dispose methods typically runs the exact
same code that the finalizer runs, plus it calls GC.SuppressFinalize.
This is saving all the CPU costs involved in running the finalizer,
plus it allows the memory to be reused sooner.

When an IDispose class does not have a finalizer, it usually has
private reference(s) to handle class(es) that do have a finalizer, so
the call to Dispose allows it to close its handle(s), thus (again)
saving all the CPU costs involved in running the handle finalizer(s),
plus allowing the memory to be reused sooner.

The only time calling Dispose doesn't save time is with the minority
of IDispose implementations that aren't avoiding a finalizer, that are
doing something like restoring the GUI cursor or noting how long it's
been since a stopwatch class has been created.

> >> > So, by calling Dispose on every object that implements it,
> >> > you are reducing memory consumption and garbage collection costs.
> >>
> >> You mean you are increasing memory consumption and garbage collection
> >> costs,
> >> not reducing them.

> >
> > No, I meant what I said. Invoking IDispose allows data to be closed
> > when you're done with, and thus avoids the use of the finalizer. The
> > finalizer is a fail-safe, but using it adds (avoidable) relocation
> > costs and means that the gc has to look at the dead object (at least)
> > twice.


--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn Great reviews & good sales.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Templates - Garbage In Garbage Not Out ramiro_b@yahoo.com C++ 1 07-25-2005 04:48 PM
Garbage Collection kamran MCSD 1 04-04-2005 10:04 PM
Garbage Collection and Manage Code? Laser Lu ASP .Net 5 01-27-2004 03:48 AM
Debbugging help! (.NET 1.1 Framework Garbage Collection Problems) Cheung, Jeffrey Jing-Yen ASP .Net 3 07-10-2003 07:29 PM



Advertisments