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.
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.
Datta KharadPosted Nov 15, 2011, 7:01 AM
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.
Vineet Kumar SainiPosted Nov 16, 2011, 7:40 PM
Please don't copy answer of anyone.If you want give a answer of any question then you can create in your mind.
Thanks...
AartiPosted Nov 16, 2011, 7:35 AM
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.
dev 0Posted Nov 15, 2011, 12:18 AM
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
Manoj SevdaPosted Nov 15, 2011, 12:02 AM
.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. /
Amit MaheshwariPosted Nov 14, 2011, 6:56 PM
i think you should follow that link which is given below,
http://msdn.microsoft.com/en-us/library/aa691138(VS.71).aspx
Sam HobbsPosted Nov 14, 2011, 5:06 PM
VulpesPosted Nov 14, 2011, 4:13 PM
Javeed M ShaikhPosted Nov 14, 2011, 3:56 PM
GC.Collect();
GC.WaitForPendingFinalizers();