Skip to content

8. JIT/NGEN, GC, Finalize()/Dispose()

February 23, 2011

22. What is JIT? What is NGEN? What are limitations and benefits of each?
The .NET Framework JIT just-in-time compiler compiles MSIL code to native code, that is the language the processor understands, binary, all 0’s and 1’s. It is CPU specific code that runs on the same computer architecture as the JIT Compiler. JIT compilation converts MSIL as needed during execution and stores the resulting native code so that it is available for subsequent calls. Basically the Just In Time compiler compiles Microsoft Intermediate Language code into native code to be executed by the processor. It’s a portable executable which provides the benefit of write once and execute everywhere. NGEN has been around since .NET Framework 1.0 release and Microsoft uses NGEN on its own core Framework assemblies. NGEN is precompilation or pre-JITing, creation of native code from MSIL on the client machine, but instead of being generated at run time it is done as a separate isolated step. NGEN is the term used for pre-JIT in the CLR, the native code produced is stored in a true Win32 PE files, that are called native images. NGEN produces faster startup and responsiveness.

23. How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization? CLR GC, Garbage Collector manages object lifetime depends on the context. The GC makes certain assumptions: the newer an object is the shorter its lifetime and vice versa the older an object is the longer its lifetime. Collecting a portion of the heap is faster than collecting the entire heap. The CLR defines 3 generations and threshholds foreach. Survival objects are promoted from one generation to the next when the GC does a compacting, this seems to be quite a Darwinian model. Non deterministic finalization is GC calls the finalize method to release memory held by the object. 2 GC processes are required to clear up finalizable objects. GC works on a separate thread and only starts when a generational threshold has been reached. There is no guarantee when Finalize will be executed. Finalizable should always implement the Dispose method to force GC to deterministically dispose of it. 

24. What is the difference between Finalize() and Dispose()?
Finalize is under the control of GC and hence the CLR. Dispose is public and can be implemented by the programmer of the class. A call to Dispose to clean up a resource triggers Finalize to be called by GC.

Happy Programing! =)

Source: mainly MSDN.

Advertisements

From → OOP

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: