Chapter 13: Using Garbage Collection and Resource Management


Chapter 13

Using Garbage Collection and Resource Management

After completing this chapter, you will be able to:

  • Manage system resources by using garbage collection.

  • Write code that runs when an object is finalized by using a destructor.

  • Release a resource at a known point in time in an exception-safe manner by writing a try/finally statement.

  • Release a resource at a known point in time in an exception-safe manner by writing a using statement.

You have seen in earlier chapters how to create variables and objects, and hopefully understand how memory is allocated when variables and objects are created (in case you cannot remember, value types are created on the stack, and reference types are given memory from the heap). Computers do not have infinite amounts of memory, so it must be reclaimed when a variable or object no longer needs it. Value types are destroyed and their memory reclaimed when the method in which they are created finishes. That's the easy bit. How about reference types? An object is created by using the new keyword, but how and when is an object destroyed? That's what this chapter is all about.




Microsoft Visual C# 2005 Step by Step
Microsoft® Visual C#® 2005 Step by Step (Step By Step (Microsoft))
ISBN: B002CKYPPM
EAN: N/A
Year: 2005
Pages: 183
Authors: John Sharp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net