Another (prolly silly) upgrade query

  • Thread starter Thread starter Jethro
  • Start date Start date
J

Jethro

Hi all

in my VB6 project, every function had a tidyup section at the end
(approximates to the "finally" contsruct in a try..catch block).

It did a SET OBJECT=NOTHING, for explicit memory release.

In .NET, is this totally redundant, and I'm best off letting the compiler
handle things ?

Thanks
 
Jethro said:
Hi all

in my VB6 project, every function had a tidyup section at the end
(approximates to the "finally" contsruct in a try..catch block).

It did a SET OBJECT=NOTHING, for explicit memory release.

This was already superfluous in VB6 at the end of a function.
In .NET, is this totally redundant, and I'm best off letting the
compiler handle things ?

What should the compiler do?


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Hi Jethro,
in my VB6 project, every function had a tidyup section at the end
(approximates to the "finally" contsruct in a try..catch block).

It did a SET OBJECT=NOTHING, for explicit memory release.

In .NET, is this totally redundant, and I'm best off letting the compiler
handle things ?

Yes, however it is more the framework that handles this for you.

However closing on the right moment is something that can be very important
in dotNet.

(And there are some things that needs to be disposed. Think for that by
instance on bitmaps and connections when it is for a network with more than
100 connections to the database).

Cor
 
* "Jethro said:
in my VB6 project, every function had a tidyup section at the end
(approximates to the "finally" contsruct in a try..catch block).

It did a SET OBJECT=NOTHING, for explicit memory release.

You didn't have to do that if the variable ran out of scope.
In .NET, is this totally redundant, and I'm best off letting the compiler
handle things ?

In 99 percent of the cases, you don't need that, if the variable runs
out of scope or if you are assigning another reference to it. In many
cases, setting a variable to 'Nothing' is contra-productive.
 
Herfried K. Wagner said:
You didn't have to do that if the variable ran out of scope.

It's a habit I was taught by the gurus where I used to work ... they had
memories of Win16 programming, and memory leaks, and made it a rule to
always explicitly release the reference ... they also sniffed at "Dim myObj
as new ..." and claimed that it should be "Dim myObj as thisClass/Set
myObj=New myClass" ....
 
Back
Top