none
HOW CLR DONE GARBAGE COLLECTION RRS feed

  • Question

  • Hi all,
            I am having some questions @ CLR
    1)How does CLR done garbage collection? How it knows which memory allocated is not
    useful for the user?
    2) Difference between Compiler and JIT Compiler?



    Thanks in advance.
    Monday, July 21, 2008 6:30 AM

Answers

  • The .NET Framework runs Gbargbe collection as a background thread that runs concurrently to check if objects, resources are still required. The Garbage collection sets a Generation Id on each object(s) that will be collected per generation. Objects gets promoted by generations. Example, if an object is in generation 0, and it survived gargbage collection the first time it ran, the object(s) is promoted to the next generation, that is 1. The heap in 0 generation will be freed for new object.  The maximum generation is 2, and older objects that survives garbage colletions are move to the next generation. You can explicitly call a garbage colletion with GC.Collect. Also you can also use GC.GetGeneration to get the generation of an object.

    An object is garbage collected when it can no longer get promoted to the next generation.

    All allocated .NET resources are stored in the managed heap, and you cannot free object from the managed heap directly until the house cleaner (Garbage collector) collectes the unreferenced object resources.

    JIT
    ---
    Just In Time Compiler, you can think of the JIT as a Runtime engine that compiles part of a code whenever it is required. When you compile your source file using the .NET compiler provided by either csc (C#), and vbc (VB.NET), you get an IL (Intermediate Language) in return. Your IL is not translated into machine readable format until is is called at runtime. Example if a certain part of your code (lets say GetHelloWorld) is called at runtime, only that part is compiled and by the JIT. So the JIT is the interpreter that sits between your IL  and the machine code.


    • Marked as answer by sunDAC Tuesday, July 22, 2008 4:25 AM
    Monday, July 21, 2008 1:43 PM

All replies

  • Looks like a homework. Get some good book and study to get these answers.

    I recommend Applied .NET Framework Programming by Jefferey Richter.

    --
    Madhur

    http://blogs.msdn.com/mahuja | Please mark the replies as answers if they help
    Monday, July 21, 2008 8:40 AM
  • The .NET Framework runs Gbargbe collection as a background thread that runs concurrently to check if objects, resources are still required. The Garbage collection sets a Generation Id on each object(s) that will be collected per generation. Objects gets promoted by generations. Example, if an object is in generation 0, and it survived gargbage collection the first time it ran, the object(s) is promoted to the next generation, that is 1. The heap in 0 generation will be freed for new object.  The maximum generation is 2, and older objects that survives garbage colletions are move to the next generation. You can explicitly call a garbage colletion with GC.Collect. Also you can also use GC.GetGeneration to get the generation of an object.

    An object is garbage collected when it can no longer get promoted to the next generation.

    All allocated .NET resources are stored in the managed heap, and you cannot free object from the managed heap directly until the house cleaner (Garbage collector) collectes the unreferenced object resources.

    JIT
    ---
    Just In Time Compiler, you can think of the JIT as a Runtime engine that compiles part of a code whenever it is required. When you compile your source file using the .NET compiler provided by either csc (C#), and vbc (VB.NET), you get an IL (Intermediate Language) in return. Your IL is not translated into machine readable format until is is called at runtime. Example if a certain part of your code (lets say GetHelloWorld) is called at runtime, only that part is compiled and by the JIT. So the JIT is the interpreter that sits between your IL  and the machine code.


    • Marked as answer by sunDAC Tuesday, July 22, 2008 4:25 AM
    Monday, July 21, 2008 1:43 PM