The way I was told is that you should never have to call garbage collection. The framework should handle it without any help from you. And at some points you using garbage collection can actually make things worse or not help at all. However, I have found times when I did need to use it (such as when doing some coding using GDI+). To call it you would add this line to your code:
VB.NET:
GC.Collect()
Again, you shouldn't need to call it though. As for where you would put it, that would really depend on what your program is doing.
Anyone know if what I said is wrong? Like I said, this is how I was taught, and if I was taught wrong I'd like to know.
You dont do it. Microsoft paid a bunch of guys a lot of money to write some artificial intelligence into the framework to work out when it's done.. All you have to do is make sure you dont have references to objects lying around that you dont use any more. When youre done with something, set it to nothing, and ensure its not referred to in any other arrays, collections etc...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.