Posts

Showing posts from June, 2015
Destructor or Finalize --- Whats the confusion?? C# really doesn't have a "true" destructor. The syntax resembles a C++ destructor, but it really is a finalizer. You wrote it correctly in the first part of your example: ~ClassName() { } The above is syntactic sugar for a Finalize function. It ensures that the finalizers in the base are guaranteed to run, but is otherwise identical to overriding the Finalize function. This means that when you write the destructor syntax, you're really writing the finalizer. According to Microsoft, the finalizer refers to the function that the garbage collector calls when it collects ("Finalize"), while the destructor is your bit of code that executes as a result (the syntactic sugar that becomes "Finalize"). They are so close to being the same thing that Microsoft should have never made the distinction. Microsoft's use of the C++'s "destructor" term is misleading, because in C++ it is executed
21147 C# ---Understanding Implementing IClonable for Deep Copies ------------------------------------------------------------------------------------- Lets say we have a class Person which refers to another class called Address . Person class contains the reference to Address class.The below is an example of implementing IClonable into classes Person and Address so that one can use clone method to us the deep copy public class Person : IClonable {     public string LastName { get; set};     public string FirstName { get ; set};     public Address personAddress {get ; set}     public object clone()     {          Person newperson=(Person)this.MemberwiseClone();         newperson.personAddress=(Address).this.personAddress.Clone();         return newperson;     } }     public class Address : IClonable {     public int housenumber {get; set};     public string streetname {get; set};     public object clone()     {     return this.MemberwiseClone();     } } Person newperson=(Person)ol
Image
21147 C# ---Understanding Managed Heap ----------------------------------------------------------------------------------------- The managed Heap is an area in virtual memory that is available for your program, that Common Language Runtime     uses for storing instances of reference type objects that are created . The original object is stored in the Managed Heap and the reference is stored in the stack. The Garbagge collector is the component of CLR that is responsible for allocating memory on the heap for the object created and also for releasing that memory when the referece no longer exists in the stack.There is a process called compaction that happens once the memory is freed and the heap is then arranged as a continuous chunk. Static Data and Constants are stored on the Heap ----------------------------------------------------------------------------------------- Static Data and constants are stored on a specific section of the Heap which is not Garbagge Collected Heap.Since bo