Saturday, June 11, 2016

.Net Framework interview questions and answers part2

6. What is Common Language Specification (CLS)?

This is a subset of the CTS, which all .NET languages are expected to support. It was always a dream of Microsoft to unite all different languages in to one umbrella and CLS is one-step towards that. Microsoft has defined CLS, which are nothing but guidelines that language should follow so that it can communicate with other .NET languages in a seamless manner.

7. What is an IL or MSIL or CIL?

Intermediate Language (IL) is also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). 
All .NET source code is compiled to IL. 
IL is then converted to machine code or at run-time by a Just-In-Time (JIT) compiler.

8. What is Garbage collection / Memory Management in .Net?


Garbage collection is automatic process performs by Garbage collector (which lives in CLR) to free up memory of objects which are no longer in used.

Every time you create a new object, the common language runtime allocates memory to store that object. But at some point that object may be no longer needed by your application. So that garbage collector deallocates memory of this type of objects, so that application can store new objects into memory. If memory is not deallocated then sooner your application will run out of memory.

Interview Questions Related to garbage collections

a. How does Garbage collection works?


Every time a garbage collection is performed, the garbage collector basically looks at the memory and frees up memory which is no longer needed, that is, memory which is occupied by ‘dead objects’.

b.  How does it know when an object is ‘dead’?

An object is dead if it is unreachable by your code. The obvious example is a local variable inside a method. There is no way for your code to access that variable once the method has returned, so it becomes ‘dead’.

C.  How often does the garbage collector perform a garbage collection?

There are three ways a garbage collection can be triggered. 
Firstly, if your system has low physical memory, this can trigger a garbage collection.
Secondly, a threshold is defined which indicates an acceptable level of memory on the heap which can be used by allocated objects. If this threshold is surpassed, then a garbage collection is triggered.
Finally, a garbage collection can explicitly be triggered by calling the GC.Collect method. Only under very rare circumstances is this ever required.

No comments:

Post a Comment