Memory used by my Application increases at each click of a mouse
-
When I run my VB.net WindowsApplication I can see that (in the Process tab of Windows Task manager) the mem usage keeps on increasing. Can someone tell me how to stop this or if we can retain the memory that was used up and no longer needed by the application. Ashfaq Maniar, Software Developer.
Ashfaq Maniar, Software Developer.
-
When I run my VB.net WindowsApplication I can see that (in the Process tab of Windows Task manager) the mem usage keeps on increasing. Can someone tell me how to stop this or if we can retain the memory that was used up and no longer needed by the application. Ashfaq Maniar, Software Developer.
Ashfaq Maniar, Software Developer.
Erhm, there's this 'thing' called the Garbage Collector, this will clean up objects which are no longer in use. If thise 'collected' objects use loads of memory, that memory will be freed, and is available again. The garbage collector is very sophisticated and i'm pretty much sure it works fine for most applications. However, as programmer, you need to 'tell' the garbage collector which objects aren't used anymore. This way you will 'help' the garbage collector finding objects to free from memory. All objects derived from the IDisposable interface, have this method called Dispose(). Dispose() will clean up all resources the object uses. If you're done using an object, call the Dispose() method so the garbage collector can do it's work. In C# the using statement helps you to not forget to call the dispose method. The example below instantiates a new object, but because i'm doing this with the using statement, the object will automatically dispose at the last bracket
using (ObjectType myObject = new ObjectType()) { myObject.DoSomething(); }
This code is by the way the same as :ObjectType myObject = new ObjectType(); myObject.DoSomething(); myObject.Dispose();
You also need to find out which of your own classes are suitable to implement the IDisposable interface to they can also dispose themselves. The garbage collector runs pretty much automaticly and you shouldn't interfere, however if you really feel like freeing memory is useful at a certain point, you can call the garbage collectors Collect() method :GC.Collect();
The collect however is pretty time-consuming and neat programmers don't need to use the Collect(). There may be exceptions to that however....: I love it when a plan comes together :. http://www.zonderpunt.nl
-
Erhm, there's this 'thing' called the Garbage Collector, this will clean up objects which are no longer in use. If thise 'collected' objects use loads of memory, that memory will be freed, and is available again. The garbage collector is very sophisticated and i'm pretty much sure it works fine for most applications. However, as programmer, you need to 'tell' the garbage collector which objects aren't used anymore. This way you will 'help' the garbage collector finding objects to free from memory. All objects derived from the IDisposable interface, have this method called Dispose(). Dispose() will clean up all resources the object uses. If you're done using an object, call the Dispose() method so the garbage collector can do it's work. In C# the using statement helps you to not forget to call the dispose method. The example below instantiates a new object, but because i'm doing this with the using statement, the object will automatically dispose at the last bracket
using (ObjectType myObject = new ObjectType()) { myObject.DoSomething(); }
This code is by the way the same as :ObjectType myObject = new ObjectType(); myObject.DoSomething(); myObject.Dispose();
You also need to find out which of your own classes are suitable to implement the IDisposable interface to they can also dispose themselves. The garbage collector runs pretty much automaticly and you shouldn't interfere, however if you really feel like freeing memory is useful at a certain point, you can call the garbage collectors Collect() method :GC.Collect();
The collect however is pretty time-consuming and neat programmers don't need to use the Collect(). There may be exceptions to that however....: I love it when a plan comes together :. http://www.zonderpunt.nl
I am using VB.net When ever a class is not usable i type class1 = nothing But the main problem is .... when a form is open and when you click anywhere on the form...the consumed memory still goes up and comes down only when the user closes the application.
Ashfaq Maniar, Software Developer.