Understanding Garbage Collection in VB.net

Slide Note
Embed
Share

Garbage collection in VB.net is a process of releasing memory from unused objects and components of the application. It is implemented as a separate thread in the .NET framework with automatic memory management. The process ensures efficient memory allocation, reclaiming of unused objects, and maintaining memory safety in applications. Conditions for garbage collection and the Mark and Compact algorithm are key aspects of the process.


Uploaded on Jul 26, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. VB.net Garbage Collection Kavita K. Bharti Assistant Professor Computer Department Durga Mahavidyalaya, Raipur

  2. INTRODUCTION INTRODUCTION Garbage releasing memory from unused objects and components of the application. .Net framework provide automatic garbage collection system. In .Net framework, it is implemented as separate thread. collection is a mechanism to

  3. There is an overhead for memory as garbage collection always runs at background. In .NET framework, garbage collection has the lowest priority. In the common language runtime(CLR), the garbage collector(GC) serves as an automatic memory manager. The garbage collector manages the allocation and release of memory for an application. Automatic memory management can eliminate common problems such as forgetting to free an object and causing a memory leak or attempting to access freed memory for an object that s already been freed.

  4. Advantages Advantages You don t need to free memory manually while developing your application. It also allocates objects on the managed heap efficiently. When objects are no longer used then it will reclaim those objects by cleaning their memory, and keeps the memory available for future allocations. It provides memory safety by making sure that an object cannot use the content of another object.

  5. Conditions for Garbage Collection Conditions for Garbage Collection Garbage collection occurs when one of the following conditions is true : The System has low physical memory. The memory that is used by allocated objects on the managed heap surpasses an acceptable threshold. This threshold is continuously adjusted as the process runs. The GC.Collect method is called and in almost all cases, you do not have to call this method, because the garbage collector runs continuously. This method is primarily used for unique situation and testing.

  6. Garbage collection process Garbage collection process Garbage collection is based on Mark and Compact algorithm. In this process, unused objects are removed and all remaining objects are compacted at the beginning of the address space. The space allotted for the application is referred to as managed heap. If there is not enough space in the managed heap for a new object then the process of garbage collection starts.

  7. To optimize the usage of garbage collector, the concept of generation is implemented. According to the concept an older object has a lower chance of getting out of scope during garbage collection. Therefore if space is needed newer objects are checked first then older objects. There are three generations Generation- 0 (Smaller in size) Generation- 1 (Medium in size) Generation- 2 (Larger in size)

  8. Generation- 0 Generation 0 contains objects that have been created since the last garbage collection. Generation- 1 Generation 1 contains objects that still remain after one garbage collection. Generation- 2 Generation 2 contains objects that are still in the scope after multiple garbage collection.

Related