Register
Sign In
Skip over navigation
Home
Add New Question
Jobs
Products
Garbage collector
Question posted
on
10 2010
Rate question difficulty level
4
1 Votes
How the garbage collector works internally tell step by step?
Add an answer
Share
|
3 Answers
Guest
In the common language runtime (CLR), the garbage collector serves as an automatic memory manager. It provides the following benefits:
Enables you to develop your application without having to free memory.
Allocates objects on the managed heap efficiently.
Reclaims objects that are no longer being used, clears 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.
Provides memory safety by making sure that an object cannot use the content of another object.
-----------------------------------------------------------------
What Happens During a Garbage Collection?
A garbage collection has the following phases:
A marking phase that finds and creates a list of all live objects.
A relocating phase that updates the references to the objects that will be compacted.
A compacting phase that reclaims the space occupied by the dead objects and compacts the surviving objects. The compacting phase moves objects that have survived a garbage collection toward the older end of the segment.
read more and credits : http://msdn.microsoft.com/en-us/library/ee787088.aspx
10/14/2010
Krishna Kireeti Kompella
• Garbage Collection works like below.
1. Garbage Collection has 3 generations. 0,1,2.
2. Memory allocation happens from 0 generation.
3. Lower the memory address higher the generation.
4. .NET Runtime checks at generation 0 and identifies the dead addresses in the memory and collects them (means clears them). The checking happens as an hierarchy. (From root address to the hierarchy).
5. If generation 0 fills with all the live adresses then to accommodate new memory allocations, addresses in the generation 0 will be moved to generation 1 and frees the generation 0 with some space.
6. If generation 1 filled with the addresses, then .NET rutime moves the addresses locations to generation 2.
7. So, Lower the address number higher the life of the memory location.
9. Lower the address number higher the generation number.
10. So, all the initial memory allocations will happen at generation 0 only.
11. But we may get a question that, if generation 2 also filled up then what is the solution. Needs to increase the Physical Memory.
10/17/2010
Keith Drew
Your explanation is almost correct however there are a couple of important issues.
Promotion of memory allocations runs after each garbage collection operation. Any allocated memory in Gen 0 is marked as Gen 1 after a single garbage collection, not when Gen 0 is full.
Also there is a large object heap that is seperate to the generations, I cannot remember the defaults, but any object that is over the default for memory consumption is placed onto the large object heap, seperate to the main memory allocation and garbage collected independantly.
As for the question of what happens when Gen 2 fills up is the system will either go into repeated garbage collection operations as it tries to clear more memory or in extreme cases a Out of Memory expception occurs. Performance monitoring can help to identify memeory issues in dotNET applications.
Adding more physical memory may not help the situation, depends on the paltform (x86 or x64) limitations. Better to solve the undelying reason as to why memory consumption is so high in the first place.
10/17/2010
Add an answer*
Your name
Email
Enter the code shown above:
please wait..
Location:
delhi
, India
Occupations:
Software\Web Development
add a question
Now hiring!
IT Sourcing Procurement Analyst Software Service Infrastructure
CVS Caremark
Woonsocket, RI
Strategy, including: Procurement Execution ?Maintain IT procurement process in collaboration with IT stakeholders ... legal risk mitigation strategy are addressed ?Support the development of executive briefings summarizing contract...
---------------------------
Software Development Analyst/ .NET Developer- Health IT
Northrop Grumman
Atlanta, GA
Sharp programming skills, eagerness for challenging development opportunities, and the ability to work with a ... of information security concepts and principles, as it pertains to application/service development and...
---------------------------
(IT Applications Analyst Developer Lead
Halliburton
Houston, TX
Houston, TX DUTIES: Responsible for the development, acquisition, maintenance and support of applications in assigned ... plus 7 years of progressive experience in Systems Development and Application Support, including analysis,...
---------------------------
Mgr Software Development 2-Health IT
Northrop Grumman
Little Rock, AR
and software developers. Works with members of the development team to ensure that all legacy data is ... years of relevant experience - Experience with IT Project Development Lifecycle - Experience converting data for...
---------------------------
IT Specialist (Applications Development)
Parsons
Houston, TX
in software complexity. Makes a recommendation to senior IT management and the end user. Uses charts, diagrams and ... guidance to lower-level IT staff assigned to an application development project. * Develops functional specifications to...
---------------------------
Software Development Engineer (IT Security)
Amazon.com
Seattle, WA
Role Description Amazon.com is looking for expert Software Development Engineers to develop tools supporting the IT ... for you. You will participate in every level of software development from requirements gathering to operational...
---------------------------
Software Development Engineer - Kindle with Special Offers, AmazonLocal
Amazon.com
Seattle, WA
Software Developement Engineer - Kindle Application Development, AmazonLocal AmazonLocal is looking for exceptional, ... or related field * 2+ years professional experience in software development * Fundamentals in object-oriented...
---------------------------
Manager Software Development 2-Health IT
Northrop Grumman
Little Rock, AR
and software developers. Works with members of the development team to ensure that all legacy data is ... years of relevant experience - Experience with IT Project Development Lifecycle - Experience converting data for...
Jobs
by
Simply
Hired
View all jobs