about Garbage collection
How do we do Garbage collection manually in our code
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vijaya KadiyalaPosted Jul 3, 2008, 1:07 PM
HI
Sample code
using System;
namespace GCCollect
{
class Account
{
public Account(string accountNumber)
{
this.accountNumber = accountNumber;
Console.WriteLine("Account::Acount - c'tor");
}
~Account()
{
Console.WriteLine("Account::~Acount - d'tor");
}
protected string accountNumber;
override public string ToString() { return accountNumber; }
};
class Class1
{
[STAThread]
static void Main(string[] args)
{
CreateAccount("111006116");
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine("Application ending");
}
public static void CreateAccount(string accountNumber)
{
Console.WriteLine("CreateAccount - instantiate Account object");
Account account = new Account(accountNumber);
Console.WriteLine("CreateAccount - created account number {0}",
account);
}
}
}
Check out the below link
http://www.developer.com/net/csharp/article.php/3343191
Thanks -- Vj
http://dotnetvj.blogspot.com
Bechir BejaouiPosted Jun 28, 2008, 4:51 AM
Niradhip ChakrabortyPosted Jun 28, 2008, 3:09 AM
to force a general garbage collection.
Check out the following URL:
http://msdn.microsoft.com/en-us/library/system.gc(VS.85).aspx