Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - How to dispose of a variable?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to dispose of a variable?

 Post Reply Post Reply
Author
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Topic: How to dispose of a variable?
    Posted: 09 October 2006 at 1:50am
Say I have this;
 
Dim myVar = Timer()
 
I then use and abuse of it and in the end when I no longer need it I want to free resources by disposing it, how do I do that?
 
Should I use;
 
myVar = Nothing
 
Or;
 
myVar = ""
 
What?
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 09 October 2006 at 3:56am
"" is an empty string. It has a string termination character and a pointer to physical address space for the string.

Nothing/Null is truly non-existant. There's no address space involved and no end-of-string character. IIRC, there's still a pointer but it's set to null.

It's a bit more efficient to set a variable to "" if you're going to reuse it later as you don't need to get a new address. If you're not going to use it later, setting it to Nothing/Null will save 32 or 64 bits of initial address space.

Remember that when a script ends, all memory space except that used by objects is rleased into the pool. The exception would be sripts invoked via server.execute or includes that will use the same memory space as the calling script.

EDIT: Stuff like timers are double-words to begin with so you gain a little more my setting them to nothing/null.


Edited by dpyers - 09 October 2006 at 4:04am

Lead me not into temptation... I know the short cut, follow me.
Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 09 October 2006 at 4:34am
Thx, great explanation. Where's the rating system?
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 09 October 2006 at 7:23am
You can't set an object to a null string unless it's a string however, the nature of VB.NET is that it is strongly typed.
The only way to get a .NET class to release its resources is to call the .Dispose() method when you're done with it.
Back to Top
scottage View Drop Down
Newbie
Newbie


Joined: 20 August 2004
Location: United Kingdom
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote scottage Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2007 at 9:09am
Mart, you can only call Dispose for those objects that support the Dispose method. A very good way of ensuring that objects are cleanly removed is to use a using block (I only code C# so I don't know if VB.net supports this)
using (IDataReader dataReader = Database.ExecuteReader())
{
while (dataReader.Read())
{
...
}
}
You can only put an object in the using block that supports the Dispose() method


Edited by scottage - 04 January 2007 at 9:10am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.