Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

4. Types and References: It’s 10:00. Do ... > If there aren’t any more references,...

If there aren’t any more references, your object gets garbage-collected

If all of the labels come off of an object, programs can no longer access that object. That means C# can mark the object for garbage collection. That’s when C# gets rid of any unreferenced objects, and reclaims the memory those objects took up for your program’s use.

  1. Here’s some code that creates an object.

    image with no caption

    For an object to stay in the heap, it has to be referenced. Some time after the last reference to the object disappears, so does the object.

  2. Now let’s create a second object.

    image with no caption
  3. Let’s take the reference to the first object, and change it to point at the second object.

    image with no caption

Typecross

Take a break, sit back, and give your right brain something to do. It’s your standard crossword; all of the solution words are from this chapter.

When you’re done, turn the page and take on the rest of the chapter.

image with no caption

Across

Down

1. The second part of a variable declaration

4. “namespace”, “for”, “while”, “using”, and “new” are examples of _____________ words

6. What (int) does in this line of code: x = (int) y;

8. When an object no longer has any references pointing to it, it’s removed from the heap using ____________ collection

10. What you’re doing when you use the + operator to stick two strings together

14. The numeric type that holds the biggest numbers

15. The type that stores a single letter or number

16. \n and \r are _______ sequences

17. The four whole number types that only hold positive numbers

2. You can combine the variable declaration and the _________ into one statement

3. A variable that points to an object

5. What your program uses to work with data that’s in memory

7. If you want to store a currency value, use this type

9. += and -= are this kind of operator

11. A variable declaration always starts with this

12. Every object has this method that converts it to a string

13. When you’ve got a variable of this type, you can assign any value to it

Answers in Typecross Solution.