Subscribe

RSS Feed (xml)

Powered By

Powered by Blogger

Google
 
xnahelp.blogspot.com

Kamis, 03 April 2008

Understanding the Garbage Collector

A big plus of writing managed code is the fact that we do not need to worry about
memory leaks from the sense of losing pointers to referenced memory. We still have
“memory leaks” in managed code, but whenever the term is used it is referring to not
decommissioning variables in a timely fashion. We would have a memory leak if we kept
a handle on a pointer that we should have set to null. It would remain in memory until
the game exits.
We should use the using statement. An example of the using statement can be found in
the program.cs file that is generated for us by the game template. The entry point of the
program uses this using statement to create our game object and then to call its Run
method. The using statement effectively puts a try/finally block around the code while
putting a call to the object’s Dispose method inside of the finally block.
Garbage collection concerns on Windows are not as large as those on the Xbox 360.
However, if we optimize our code to run well on the Xbox 360 in regard to garbage
collection, the game will also perform well on Windows.

0 komentar: