Q: How long does the garbage collection take?
A: That's going to depend on a number of factors, including what code
was placed in the Dispose method of objects that the GC has to dispose
of on its own. You can't nail it down to a finite number, because you
never know what someone ELSE is doing. However, the collector is highly
optimized, and should be able to efficiently release upwards of 40
million objects per second. Again, that number can be reduced if a
Dispose method does something processor intensive (e.g., commit a
transaction).
------------------------------------------------------------
Q: If I don't release objects (in critical times) does the garbage
collector run at all?
A: The garbage collector runs regardless of what your code does. The GC
runs on a low-priority thread, and checks for unreferenced dynamically
allocated memory space. If any piece of dynamically allocated memory
can't be referenced from a variable currently on the stack, that object
is collected. If the object has a Dispose method, it's invoked in the
first pass. It's actually deleted on the 2nd pass.
Note that you can force the garbage collector to run by invoking
System.GC.Collect(). It's not recommended that you do that too often,
however, and never without good reason. It's a low-priority thread for
a reason.
------------------------------------------------------------
Q: Does the code get compiled at application start, or on first
execution of a function?
A: I've seen no documentation that indicates that code is JIT-compiled
on a per-function basis. The documentation that I have seen states then
when you compile a program in Visual Studio, the .EXE file actually
contains MSIL, which is (supposedly) platform independent. That MSIL
gets JIT compiled to native code when you start the application. Each
assembly referenced by the application is JIT compiled as it is needed
(and only if it hasn't been NGENed); however, once an assembly has been
JIT compiled, the native version is used to execute it. If your restart
the application, it's JITted again.
It is important to note that you can bypass the JIT step and improve
performance by using NGEN, which ships with .NET. A quick article about
how to use NGEN can be found here:
http://visualbasic.about.com/od/usingvbnet/a/FWTools2.htm
------------------------------------------------------------
I'm right there with you about why I prefer to use .NET: I am a huge
proponent of typesafe languages, and the CLR is *extremely* type-safe.
That makes my code more efficient and far more robust, and makes me do
more upfront thinking than I would with typeless languages (like
JavaScript) or relatively dynamic languages (like Visual Basic 1-6).
Then there's the fact that it's truly object-oriented, which is far
better (IMHO) than object-BASED VB6.
Cheers!