thanks!
<%
sub foo()
dim objDict
set objDict = CreateObject("Scripting.Dictionary")
...
set objDict = nothing
end foo
function bar()
dim objRS
set objRS = Server.CreateObject("ADODB.Recordset")
...
call objRS.Close()
set objRS = nothing
bar = <some value>
end bar
%>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
the interpreter should clean up, but it would never hurt to do it yourself
and then you don't have to worry about whether it happens or not or if
different revs handle it the same way. the bottom line is that you should
always clean up any resources you allocate yourself whether the system would
do it for you or not.
thanks, bob.
i am pretty anal about setting them to Nothing but (1) i wanted to be sure
that if i accidentally slipped and missed a couple in a function or two it
wouldn't kill me, and (2) was trying to see if i could skip it altogether if
it was common-knowledge that it was only needed in certain (assumed rare)
cases.
it gets to be a real pain and adds a lot of clutter to a routine which has a
lot of error-checking code that needs to clean-up a smattering of objects at
every exit point; at the end of the routine it isn't too much of a problem,
however.
For example,
Sub Foo()
Dim MyObj
set MyObj = CreateObject("Extremely.Expensive.Object")
MyObj.Blah(123)
' MyObj is never used for the rest of the function
Set MyObj = Nothing
' [A huge amount of code here]
End Sub
Now suppose Foo is called by the server dozens of times on dozens of
threads, often at the same time. If you don't set MyObj to Nothing, then
MyObj will be alive until Foo ends, a potentially very long time if Foo is
an expensive function. That means that the total time that large amounts of
resources are consumed becomes much larger as the system gets loaded. By
throwing away the object when you know you are done with it, you greatly
reduce the time that the resources are held.
--> This is particularly important if the resources held by your object are
synchronized. <-- You want synchronized resources to be freed ASAP so that
some other blocked thread can grab them.
Eric
st...@yohanan.org wrote in message <6u107h$3cc$1...@nnrp1.dejanews.com>...
>in vbscript under ASP, do i need to clean up any objects i use within a
>subroutine or function before returning from it? for example, do i need to
>set the objects to Nothing in the following routines or will the
interpreter
>do the clean-up for me when i return from them?
>
>thanks!
>
><%
>sub foo()
> dim objDict
> set objDict = CreateObject("Scripting.Dictionary")
> ...
> set objDict = nothing
>end foo
>
>function bar()
> dim objRS
> set objRS = Server.CreateObject("ADODB.Recordset")
> ...
> call objRS.Close()
>
> set objRS = nothing
>
> bar = <some value>
>end bar
>%>
>
sub foo()
dim obj
set obj = CreateObject("some.object")
...
if (some condition is true) then
set obj = Nothing
exit sub
end if
...
set obj = Nothing
end foo
thanks!
In article <OQb7WXz...@uppssnewspub04.moswest.msn.net>,