how garbage collector frees object



hi To all ,

I want to know about garbage collector & freeing memory of objects
i have writened one sample program and in that i created one destructor
something like this

using System;
class Point
public double x, y;
public Point() {
this.x = 0;
this.y = 0;
Console.WriteLine("destructed {0}",this);
public Point(double x, double y) {
this.x = x;
this.y = y;
public static double Distance(Point a, Point b) {
double xdiff = a.x - b.x;
double ydiff = a.y - b.y;
return Math.Sqrt(xdiff * xdiff + ydiff * ydiff);
public override string ToString() {
return string.Format("({0}, {1})", x, y);
class Test
static void Main() {
Point a = new Point();
Point b = new Point(3, 4);
double d = Point.Distance(a, b);
Console.WriteLine("Distance from {0} to {1} is {2}", a, b, d);
Console.WriteLine("terminating prog");

the output of this prog is

Distance from (0, 0) to (3, 4) is 5
terminating prog
destructed (3, 4)
destructed (0, 0)

it means that on termination of prog all objects held by program are freed
b,caus destructor is called only when object are freed
but according to specification object are freed by garbage collector only
so does it mean on termination of program garbage collectors are called
& if it is so then i think to run garbage collector all operation on heap
should be susspended temporarily then on web server like thing there may be
large no of program running

Any replyes on this will be appreaciated '

i also want to know that how memopry is alocated for intefaces,or abstract

Have a Nice Day,


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question