Game Development Reference
In-Depth Information
The algorithm used by the CLR garbage collector is fairly straightforward, but has
been optimized extensively. When a collection occurs, the GC starts with the
assumption that all objects in the heap are garbage. It begins building a hierarchi-
cal graph of the roots and walks the tree to determine which objects cannot be
accessed by the application. Objects that are unreachable from the application are
considered garbage and can be removed during the next collection. The GC then
walks the roots in a linear fashion, looking for contiguous blocks of memory that
can be freed. The garbage is removed and all the remaining objects are shifted
down in memory to remove gaps in the heap.
Allocation Profile
The level of exertion required by the garbage collector to handle the memory of a
managed application is known as an allocation profile, which is a function of the
object allocation count, the lifetime of each object, and the size of the allocations.
As the level of exertion increases, so does the number of processor cycles the
garbage collector takes, resulting in less time for the processor to run the applica-
tion code. There are a couple techniques to optimize the allocation profile for your
application, alleviating a good percentage of overhead as a result of garbage col-
lection.
The most apparent way to relieve pressure is by allocating fewer objects. While the
object-oriented paradigm introduced many great design and development con-
cepts, it also resulted in a vast increase in the number of objects used to solve a
problem.
An allocation profile is known to be either friendly or unfriendly with the garbage
collector. An unfriendly profile will have many short life span objects allocated in
the Large Object Heap, or many objects surviving in generation 2 for a long time
before being collected. Objects in older generations that reference objects in
younger generations increase the level of exertion by the garbage collector to man-
age collection. A friendly profile will allocate most of the objects when the appli-
cation loads for the first time, and other objects will have a short life span and exist
mainly in generation 0. Additionally, any objects with a long life span will contain
few or no references to objects with a short life span.
It is important that you determine and constantly tune your allocation profile so
that you can eliminate many performance issues as a result of automatic garbage
collection.
Search Nedrilad ::




Custom Search