C# Programming - Constructors - Discussion
Discussion Forum : Constructors - General Questions (Q.No. 11)
11.
Is it possible to invoke Garbage Collector explicitly?
Discussion:
9 comments Page 1 of 1.
Karishma sahu said:
1 decade ago
True, we can call GC using System.GC.Collect() method.
(1)
Irfan said:
1 decade ago
By using destructor.
Anusha said:
1 decade ago
By using GC.Collect() method.
Usha said:
1 decade ago
Dispose method is used to explicitly invoke a destructor.
Sujeettiwari said:
1 decade ago
@Ausha you are correct.
Swami said:
1 decade ago
How it is possible, I don't understand could you explain. ?
John said:
1 decade ago
// Put some objects in memory.
MyGCCollectClass.MakeSomeGarbage();
Console.WriteLine("Memory used before collection: {0:N0}",
GC.GetTotalMemory(false));
// Collect all generations of memory.
GC.Collect();
Console.WriteLine("Memory used after full collection: {0:N0}",
GC.GetTotalMemory(true));
MyGCCollectClass.MakeSomeGarbage();
Console.WriteLine("Memory used before collection: {0:N0}",
GC.GetTotalMemory(false));
// Collect all generations of memory.
GC.Collect();
Console.WriteLine("Memory used after full collection: {0:N0}",
GC.GetTotalMemory(true));
Somnath said:
1 decade ago
@Usha is right Dispose method is used to explicitly call GC.
Sam said:
9 years ago
Yes, we can do it either by "using " statement or inheriting ID is possible interface.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers