C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Garbage Collection(GC) - An introduction


Posted Date: 22 May 2004    Resource Type: Articles    Category: .NET Framework
Author: Sajid P KMember Level: Gold    
Rating: 1 out of 5Points: 12



One of the major causes of program failure today, particularly in applications that run for long time is due to manual memory management. Which leads two main problems :

First one is, a programmer allocates a block of memory in a data storage area of the operating system (i.e. in Random Accesses Memory) intending to free it later, but forgets to free the memory it no longer needs. This condition popular as ‘Memory leak’

If an application runs long enough, these leaks accumulate and the application runs out of memory, which may not be a big deal in light programs like ‘notepad’, which the user runs for only a few minutes an then shuts-down. But a large applications, like web servers, that are supposed to run continuously for days or weeks, accumulation of memory leaks lead to crashes.

Second one: A programmer manually deletes an object but then mistakenly or other objects tries to access this memory location later. The application tends to hang, and more over transistors that had make up the deleted object memory would still contain ‘Plausible’ values, and the process continues to run with corrupted data.

The above mentioned problems are worse than most other application bugs because of the consequences and their unpredictable occurrences. That is, making our application unpredictable at unpredictable times.

Microsoft.NET provides a solution. It has made automatic memory management a part of .Net common language runtime (CLR). This allows it to be used in any .NET language. That is in .NET application if CLR detects that an application is no longer using the memory or that it is no longer needed, memory is released (i.e. Application does not have to explicitly free Memory that allocated). This mechanism runs automatically in background and is known as Garbage Collection

It solves the problem of manual memory management without having to write any code. You can afford to forget to delete an object because the system cleans it for you when it is not required and you can’t access deleted objects through an invalid reference because the object won’t be deleted as long as you hold a reference to it.

This Garbage Collection is like an automatic seat belt. The passengers couldn’t forget to buckle it. Moreover, we know that automatic belt require more space and mechanisms than manual one. Similarly .NET applications require more system resources than ordinary applications.

The garbage collection feature changes the way we code. We don't have the Free All That we Create overhead, so our code is smaller and clearer and easier to write. Garbage collection also makes programming more object oriented.

Main aim of .Net is to facilitate faster development with fewer bugs.

NOTE: The memory used by heap variables is freed via a process called garbage collection. Stack variables is automatically freed when the method in which they were created returns( ie Grabage collection is applied only for Heap Variables)


In the next article, i will explain the working of Garbage Collection.

Psaj, NITC




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Introduction to GC  .  Introduction to Garbage Collection  .  GC in .NET  .  Garbage Collection in .NET  .  Garbage Collection  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Compiling source files and building assemblies from command prompt
Previous Resource: XML serialization and Binary serialization
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use