With a managed application, blocks of memory are allocated on the managed heap. (The heap is the part of memory that is used to store objects, as opposed to the stack, which is used to store references to objects— more on heap and stack later.) The GC keeps track of the referenced objects on the heap and automatically frees up the memory allocated to a specific object when it goes out of scope. Calling the GC programmatically is possible by invoking the method System.GC.Collect. However, this is not recommended because it is not guaranteed that it will destroy your objects. It is best to focus on the business logic and let the CLR determine the right time for garbage collection.
A blog about Latest Technology News, Technology Videos, Computer Tips, Web Programming, Technology Events, SEO and further IT topics.
Wednesday, November 10, 2010
The .NET Framework - Garbage Collection
One of the most important benefits of using managed applications is the use of the garbage collector (GC). The role of CLR does not end after compiling the IL code into native code. In fact, the CLR is responsible for managing memory during the code execution. It assures that the memory used by the program is totally freed up after the program exits. With unmanaged applications, programmers are responsible for managing the memory and resolving problems that might occur if a block of memory is left allocated after the program ends.
With a managed application, blocks of memory are allocated on the managed heap. (The heap is the part of memory that is used to store objects, as opposed to the stack, which is used to store references to objects— more on heap and stack later.) The GC keeps track of the referenced objects on the heap and automatically frees up the memory allocated to a specific object when it goes out of scope. Calling the GC programmatically is possible by invoking the method System.GC.Collect. However, this is not recommended because it is not guaranteed that it will destroy your objects. It is best to focus on the business logic and let the CLR determine the right time for garbage collection.
With a managed application, blocks of memory are allocated on the managed heap. (The heap is the part of memory that is used to store objects, as opposed to the stack, which is used to store references to objects— more on heap and stack later.) The GC keeps track of the referenced objects on the heap and automatically frees up the memory allocated to a specific object when it goes out of scope. Calling the GC programmatically is possible by invoking the method System.GC.Collect. However, this is not recommended because it is not guaranteed that it will destroy your objects. It is best to focus on the business logic and let the CLR determine the right time for garbage collection.
Labels:
C#,
C++,
Free Quickbooks,
learn earn
Popular Posts
-
To create a new document, select File > New or press Ctrl+N/Cmd+N. This opens the New Document dialog box, which has been considerably r...
-
The first new product, Nokia C3, made in a candybar with a QWERTY-keyboard and is based on the platform S40. The phone has a 2.4-inch t...
-
The Common Language Runtime is responsible for executing applications and runtime services such as language integration, security enforcemen...
-
When you buy Visual Studio 2005, you get the full-featured integrated development environment (IDE). You can also get a free C# compiler by...
-
MSIL and JIT When you compile a C# program, the compilation does not directly generate native (operating system-specific) code; it generate...