I am working with this code as an example:
var p = new person("Amir");
var zp = new person("Amiraa");
GC.Collect();
GC.WaitForPendingFinalizers();
class person
{
public person(string nName)
{
Console.WriteLine("New");
string name = nName;
}
~person()
{
Console.WriteLine("Garbage collected");
}
}
But the resault on the console only shows "New", not "Garbage collected". so why is the gc not working?