Declaring a garbage collector

  • Thread starter Thread starter Adam Honek
  • Start date Start date
Like in Java where they have a sub that's called when the program is to
terminate.

It releases any used resources and basically cleans up.

Adam
 
Adam,

That is one of the main differences between Java and Net and why it is
called Managed Code. Net does that for you on the best time. You would not
wanted to force that. (Which is possible, however will cost a lot of total
throughput time)

Cor
 
Cor Ligthert said:
That is one of the main differences between Java and Net and why it is
called Managed Code. Net does that for you on the best time.

Java and .NET have similar garbage collectors...
 
Herfried,

If I had not you,

This is was what I had understood from our Java Guru in these newsgroups, I
probably have understood him wrong.

Cor
 
Hello Adam

let me try to shine some light on the subject :-)


In java when you want to invoke the GC you need to do this

Runtime objFoo = Runtime.getRuntime();
objFoo.gc();


in .Net however the GC is in the system namespace
so the equivalant for above java code would be GC.Collect()

However as Cor mentioned calling the GC.Collect method to cause an induced
garbage collection is usually a bad idea

The only valid situation i can think of is when the application is idle and
if you see that unexpected garbage collections are slowing down the
application during time critical operations ( example : your program is in
charge of controling hardware devices that require a short response time )

In all other situations i would say , let the GC doe it`s work as how it was
intended to do so , as this gives you the highest performance

Regards

And happy coding :-)

Michel Posseth [MCP]
 
Use the Closing or Closed events. (FormClosing or FormClosed in .NET 2.0).

The first one occurs before the form is closed, and gives you the
opportunity to stop the form from closing. The second one occurs after
the form is closed.
 
Adam,
It sounds like you want to declare a Finalizer.

A Finalizer is used to "releases any used resources and basically cleans
up".

Generally if you are declaring a Finalizer you also want to implement
IDisposable.

For more infor on implementing Finalizers & Disposable see:

http://msdn.microsoft.com/msdnmag/issues/04/05/NETMatters/

http://msdn.microsoft.com/library/d...guide/html/cpconImplementingDisposeMethod.asp

http://msdn.microsoft.com/library/d.../en-us/cpgenref/html/cpconFinalizeDispose.asp


--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Like in Java where they have a sub that's called when the program is to
| terminate.
|
| It releases any used resources and basically cleans up.
|
| Adam
|
| | > Adam,
| >
| > Can you tell more what you mean with "a" garbage collector?
| >
| > Cor
| >
| > "Adam Honek" <[email protected]> schreef in
bericht
| > | >> Hi,
| >>
| >> Is there a way to delcare a garbage collector in VB.NET 2005?
| >>
| >> Thanks,
| >> Adam
| >>
| >
| >
|
|
 
Back
Top