Hi..
I want to know name of keyword ,which is used for deallocation memory in .NET ?
Thanks...
Loading
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 attend5days leftRegister
Datta KharadRank #2,135 · 668 reputationPosted Nov 15, 2011, 2:01 AM EST
1) GC.Collect():-
The C# language is a garbage-collected language, which means that memory that is no longer referenced by your program will be reclaimed and can later be reused. With the GC.Collect method, you can force a garbage collection to occur at any time. GC.Collect method is not useful because it often has little benefit and might even reduce performance, while increasing complexity and causing you headaches.
2) Dispose() :- Dispose method is used to release unmanaged resources when unmanaged resources are no longer in use.And Programmers should keep in mind at the time of codeing(using dispose method) for best memory management.
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 14, 2011, 10:56 AM EST
GC.Collect();
GC.WaitForPendingFinalizers();
VulpesRank #55 · 29.2K reputationPosted Nov 14, 2011, 11:13 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Nov 14, 2011, 12:06 PM EST
Amit MaheshwariRank #475 · 5.2K reputationPosted Nov 14, 2011, 1:56 PM EST
i think you should follow that link which is given below,
http://msdn.microsoft.com/en-us/library/aa691138(VS.71).aspx
Manoj SevdaRank #1,670 · 916 reputationPosted Nov 14, 2011, 7:02 PM EST
.NET uses a garbage collector to clean up memory on the heap. With each collection cycle, variables and objects that are no longer reachable by code are discarded automatically. If You want to clean up memory explicitly then you can use using method. For example
using (MyObject myObject = new MyObject())
{
// use your object
}
in this process your MyObject have to inherited with Idisposable Interface, which is explicitly dispose the object when object scope was ended.
In Other Words..
If the object implements IDisposable, then you need to call Dispose. For example, if you go new FileStream(...), then the FileStream needs to be disposed, since it implements IDisposable. I would suggest you read up on the using construct in C# which makes it easier to handle IDisposable objects.
Not really, 99.99% of the time, the garbage collector will know when the best time to run is. It's one of those, "you'll know when you need it" kind of situations.
When the object containing the event is no longer referenced, then logically any object references contained in the event are also no longer referenced and will be available to be collected. /
dev 027 reputationPosted Nov 14, 2011, 7:18 PM EST
The let us Keyowrd in .net 4.0 is Using for deallocate the memory , so we dont need to call dispose function, this Using keyword deallocate memory , in short it calls garbage collector.
Hope this will help you.
Thanks
AartiRank #2,383 · 594 reputationPosted Nov 16, 2011, 2:35 AM EST
To Deallocate memory in Dot Net,wwe first call GC.Collect() then Dispose() method.
1) GC.Collect():-
The C# language is a garbage-collected language, which means that memory that is no longer referenced by your program will be reclaimed and can later be reused. With the GC.Collect method, you can force a garbage collection to occur at any time. GC.Collect method is not useful because it often has little benefit and might even reduce performance, while increasing complexity and causing you headaches.
2) Dispose() :- Dispose method is used to release unmanaged resources when unmanaged resources are no longer in use.And Programmers should keep in mind at the time of codeing(using dispose method) for best memory management.
Thanks.
Vineet Kumar SainiRank #257 · 9.8K reputationPosted Nov 16, 2011, 2:40 PM EST
Please don't copy answer of anyone.If you want give a answer of any question then you can create in your mind.
Thanks...