Microsoft Exam Questions

Which code segments should you include in Target 1 and …

DRAG DROP
You are creating a class named Data that includes a dictionary object named _data.
You need to allow the garbage collection process to collect the references of the _data object.
You have the following code:

Which code segments should you include in Target 1 and Target 2 to complete the code? (To answer, drag the
appropriate code segments to the correct locations in the answer area. Each code segment may be used once,
more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Select and Place:

Answer:

Explanation:
* WeakReference influences the garbage collector. Most objects that are referenced must be kept in memory
until they are unreachable. But with WeakReference, objects that are referenced can be collected.
* Example: C# program that uses WeakReference
using System;
using System.Text;
class Program
{
/// <summary>
/// Points to data that can be garbage collected any time.
/// </summary>
static WeakReference _weak;
static void Main()
{
// Assign the WeakReference.
_weak = new WeakReference(new StringBuilder(“perls”));
http://www.dotnetperls.com/weakreference