In this article I have shared some points related to .NET Garbage Collector as follows..
1. Destructor
2. Idisposable interface and Pattern
3. Using block
4. Dispose vs Finalize
5. GC (Garbage Collector)
Some key points to remember about GC.
1. GC is a.net framework thread, which run in background.
2. GC check for all the objects which has destructor, if found then it will place them in another list named as Finalization List.
3. GC create two thread,
The first thread:
- Which are reachable list (All reachable object are clared one after one from the heap list and this it reclaim the memory)
- Another which are not (which are not reachable is known as finalization list)
- which reads the finalization lists and calls, the each object finalized in separate object.
- Gen 0 Object reach ~256KB keep
- Gen 1 objects reach ~2Meg
- Gen 2 objects reach ~10meg
- System memory is low.
- .NET c#,vb Classes are known as Managed Object. All those which has been created using .net language, gc treated as a managed code.
- (vb6, com ,windows, connection, files) all these type of code or we can say non .net developed code are known as unmanaged code.
- Checking frequency in the Finalize queue is very less as compare to gen (0,1,2,) bucket.
- By defining the destructor you can define the finalize method.
- When Code is complied the distructor will convert into the finalize automatiocally. gc treat this as a finalize, Moreover, in .net reflector you can see that after compilation the destructor convert into finalize method.
- We can not call directly finalize method because developer don't have any access to finalize .
- Only GC has the rights and facility to call the finalize method.
- Destructors (~) cannot be defined in Structs.
- Destructors (~) are only used with classes.
- Destructor cannot be inherited or overloaded.
- Destructor does not take modifiers or have parameters.
- Destructor cannot be called. They are invoked automatically.
- An instance becomes eligible for destruction when it is no longer possible for any code to use the instance.
- The Programmer has no control over when destructor is called because this is determined by Garbage Collector.
- Destructor is called when program exits.
- Execution of the destructor for the instance may occur at any time after the instance becomes eligible for destruction.
- Destructor implicitly calls Finalize on the base class of object.
No comments:
Post a Comment