Click here to Skip to main content
12,759,844 members (29,757 online)
Rate this:
Please Sign up or sign in to vote.
See more: .NET
I am trying to understand how .net CLR work, I listed how it work as far as I know(Maybe there are some mistake, please feel free to point out), and have some questions below.

1, When .Net Compiler compile .net application source code, it will select whatever language compiler.Than creates dll or exe assembly, which includes CIL, Metadata and Manifest.

2, In Manifest, it tells which outside library I need to use. So the library(or other dll) loaded.

3, JIT translate CIL to machine language which the computer can run the application. JIL also check the code safety.

My questions are:
1, Is the CLR run as I mentioned above?

2, I know that the CLR also responsible for Automatic memory management and Garbage Collection. When CLR do those thing?
Posted 2-Jan-13 12:45pm
This is very rare case when I vote 5 for the question.

I can only repeat that the question are accurately formulated and probably show your intent to get the essence of things. Unfortunately, these days this is quite rare. I answered all your questions so far, and in all three cases I up-voted it with pleasure.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Let's see:
  1. Pretty much so, but not quite exactly when you write about the JIT operation. Usually, the code is JIT-compiled on per-method basis. When some method is about to be called for the very first time in the lifetime of its assembly, it is JIT-compiled.

    It can be pre-compiled if you use NGEN.EXE, which can be done for some performance benefits, for example:[^].

    This is a very interesting in-depth CodeProject article on JIT optimization: JIT Optimizations[^].

  2. Memory management is and garbage collection work pretty much all the time; their operation is independent from the application process and transparent to it. The general rule is: you can never rely on any particular order of operation.

    You can prevent memory management operations when you pin some memory. This is done by using fixed statement. Please see:[^].

    There are a number of cases when you really need pinning. Normally, you do it only if you directly use pointers in an assembly compiled with unsafe option in the code under unsafe statement:[^].

    Again, this is an interesting in-depth CodeProject article on pinning: Pinned Object[^].

    And now, about GC. The operation of GC is driven by the reachability of objects. The actual call of the object destructors and the act of reclaiming memory cannot be predicted bu the application (by the way, this is the reason why destructores are rarely written in the typical .NET applications, usually this is not needed and can created some problems of race conditions type), but it happens when some object becomes unreachable.

    By the way, this is not so trivial criterion as you might think. For example, if object A references object B, object B references object C, and C reference A, this cyclic dependency does not prevent GC from figuring out that all objects should be garbage-collected if there are no other referenced to them. This is easy to check up by a simple experiment.

    You can find the detail of reachability and garbage collection here:[^].

Good luck,
Andreas Gieriet 2-Jan-13 18:22pm
Excellent answer!
My 5!
Thank you, Andi.
Chelseajcole 3-Jan-13 10:31am
Thank You Very Much for The Answer!! And Happy New Year!
You are very welcome.
Happy New Year!
Call again,
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Memory management happens when it feels like it. This is not good enough if you use large objects in memory, like videos. It's fine for most applications.

It has nothing to do with the compilation process that you listed. It's something else entirely.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100