- C# 7 and .NET Core 2.0 High Performance
- Ovais Mehboob Ahmed Khan
- 303字
- 2021-08-27 18:47:13
Garbage collection
One of the most important features of CLR is the garbage collector. Since the .NET Core applications are managed applications, most of the garbage collection is done automatically by the CLR. The allocation of objects in the memory is efficiently done by the CLR. The CLR not only tunes the virtual memory resources from time to time, but it also reduces the fragmentation of underlying virtual memory to make it more efficient in terms of space.
When the program is run, the objects start allocating memory on the heap and each object's address is stored on the stack. This process continues until the memory reaches its maximum limit. Then the GC comes into play and starts reclaiming memory by removing the unused managed objects and allocating new objects. This is all done automatically by the GC, but there is also a way to invoke the GC to perform garbage collection by calling the GC.Collect method
Let's take an example where we have a Car object called c in the Main method. When the function is executed, the Car object will be allocated by the CLR into the heap memory and the reference to that c object will be stored in the stack address pointing to the Car object on the heap. When the garbage collector runs, it reclaims the memory from the heap and removes the reference from the stack:

Some important points to note are that the garbage collection is done automatically by the GC on managed objects, and that if there are any unmanaged objects, such as database connections, I/O operations, and so on, they need to be garbage collected explicitly. Otherwise, GC works efficiently on managed objects and ensures that the application will not experience any decrease in performance when the GC is performed.
- 公有云容器化指南:騰訊云TKE實戰(zhàn)與應(yīng)用
- 文本挖掘:基于R語言的整潔工具
- 區(qū)塊鏈通俗讀本
- Python數(shù)據(jù)分析:基于Plotly的動態(tài)可視化繪圖
- 數(shù)字媒體交互設(shè)計(初級):Web產(chǎn)品交互設(shè)計方法與案例
- 基于OPAC日志的高校圖書館用戶信息需求與檢索行為研究
- 從0到1:JavaScript 快速上手
- 重復(fù)數(shù)據(jù)刪除技術(shù):面向大數(shù)據(jù)管理的縮減技術(shù)
- 淘寶、天貓電商數(shù)據(jù)分析與挖掘?qū)崙?zhàn)(第2版)
- Unreal Engine Virtual Reality Quick Start Guide
- SIEMENS數(shù)控技術(shù)應(yīng)用工程師:SINUMERIK 840D-810D數(shù)控系統(tǒng)功能應(yīng)用與維修調(diào)整教程
- Rust High Performance
- Trino權(quán)威指南(原書第2版)
- SQL必知必會(第四版)
- 新一代信息技術(shù)基礎(chǔ)