About Garbage collection
How do we do Garbage collection manually in our code
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Jun 27, 2008, 11:09 PM EDT
to force a general garbage collection.
Check out the following URL:
http://msdn.microsoft.com/en-us/library/system.gc(VS.85).aspx
Bechir BejaouiRank #144 · 15.9K reputationPosted Jun 28, 2008, 12:51 AM EDT
Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Jul 3, 2008, 9:07 AM EDT
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