Hi people,

A really noob question but I thought that I should find the answer to it in any case.

There was always much noise made about JAVA's inherent speed and some of that speed being attributed to the inbuilt so called garbage collection. Having learned first to program in JAVA at uni I am now developing a program in VB 6. I saw somewhere in my wonderings through the web (might have even been in this forum) that you should set your objects to nothing when you are done "otherwise you will really hate yourself".

This is like wiping the counter after making a sandwich I guess. I would like to know if that is really true of VB and in what circumstances it would apply.

Should it only be objects as a sort of de-constructor or should one for instance have each sub setting all the local variables it created to "nothing" before the sub/function ends?

Thanks to anyone who doesn't mind pointing me in the right direction with regard to this.

Cheers.

That's a quite large topic.

Normal scope/out of scope rules apply to variables i.e. when (local) variable goes out of scope, it's destroyed automatically. Class implementations should implement destructor (Class_Terminate event) to clean up allocated resources. The same applies to every reference you make to resources, like database connection objects. They should be set explicitly to Nothing, so that at the some point GC can kick in and return used memory areas to heap.

A short answer to your question is, no for local variables, yes for object references. This is not by any means a comprehensive answer anyway :)

BTW, this is VB.NET forum, your question should be in Visual Basic 4/5/6 forum.

Hmm, all the way back to VB6 eh -

Actually you might get a better answer in the VB 4|5|6 forum than in the .Net forum. Garbage collection is different in VB6 from .Net

Well thanks anyway guys. I appreciate the answers even if I didn't post it in the right forum.

cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.