
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How does Garbage Collector work in C#
The garbage collector (GC) manages the allocation and release of memory. The garbage collector serves as an automatic memory manager.
You do not need to know how to allocate and release memory or manage the lifetime of the objects that use that memory.
An allocation is made any time you declare an object with a “new” keyword or a value type is boxed. Allocations are typically very fast.
When there is not enough memory to allocate an object, the GC must collect and dispose of garbage memory to make memory available for new allocations.
This process is known as garbage collection.
Garbage Collection in C# has the following advantages −
You do not 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 clearing their memory, and keeps the memory available for future allocations.
Managed objects automatically get clean content to start with, so their constructors do not have to initialize every data field.
- Related Articles
- How does garbage collection work in Python?
- Python Garbage Collector interface (gc)
- How does Garbage Collection work in Lua Programming?
- How many ways to call garbage collector (GC) in Java?\n
- Do you think garbage collector can track all the Python objects?
- How does #include work in C++?
- How does a vector work in C/C++
- How does a vector work in C++?
- What is garbage? What does garbage consist of?
- How does the Comma Operator work in C++
- How does generic lambda work in C++14?
- How does the compilation/linking process work in C/C++?
- How to force garbage collection in C#?
- How does jQuery.scrollTop() work?
- How does jQuery.scrollLeft() work?
