473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ASP - Terminating objects in memory

Hi,

In ASP, is it absolutely necessary to set an object to Nothing after
being used?

set myObj = server.createObject("myDLL.myClass")
call myObj.useClass
set myObj = Nothing <--- can I omit this?

I'm dealing with a large number of files with nested includes. There
are many places where I use the object, I want to avoid initializing
the object any more than necessary, and I want to change as few pages
as possible. The simplest way for me to do this is to not set the
object to nothing. Will ASP implicitly remove the object from memory,
or will I have a memory leak?

~ L

Jul 26 '06 #1
8 2024

"Lauren the Ravishing" <la******************@yahoo.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi,

In ASP, is it absolutely necessary to set an object to Nothing after
being used?

set myObj = server.createObject("myDLL.myClass")
call myObj.useClass
set myObj = Nothing <--- can I omit this?

I'm dealing with a large number of files with nested includes. There
are many places where I use the object, I want to avoid initializing
the object any more than necessary, and I want to change as few pages
as possible. The simplest way for me to do this is to not set the
object to nothing. Will ASP implicitly remove the object from memory,
or will I have a memory leak?

~ L
ASP will implicitly call the release method on any interface pointer
currently held by a variable when it passes out of scope. This includes
when the script has completed resulting in the script context being reset.

Not using set to nothings will not, of itself, introduce a memory leak.
However there is no harm in using set to nothing either and some developers
consider it good practice (I'm not one of them though).

Anthony.
Jul 27 '06 #2

Anthony Jones wrote:
"Lauren the Ravishing" <la******************@yahoo.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi,

In ASP, is it absolutely necessary to set an object to Nothing after
being used?

set myObj = server.createObject("myDLL.myClass")
call myObj.useClass
set myObj = Nothing <--- can I omit this?

I'm dealing with a large number of files with nested includes. There
are many places where I use the object, I want to avoid initializing
the object any more than necessary, and I want to change as few pages
as possible. The simplest way for me to do this is to not set the
object to nothing. Will ASP implicitly remove the object from memory,
or will I have a memory leak?

~ L

ASP will implicitly call the release method on any interface pointer
currently held by a variable when it passes out of scope. This includes
when the script has completed resulting in the script context being reset.

Not using set to nothings will not, of itself, introduce a memory leak.
However there is no harm in using set to nothing either and some developers
consider it good practice (I'm not one of them though).
Why is it considered "good practice" by some?

--
Mike Brind

Jul 27 '06 #3
Mike Brind wrote:
Why is it considered "good practice" by some?
Some of the reasons I've seen cited include:

1. Being in control of when objects are created and released - this is the
one I used to see most often in the "x tips for writing code" lists I used
to read in books and on the web.The upshot being that one could not consider
oneself to be a "good" programmer if this level of control was not retained.
This tip was usually about the recommendation against using the VB "dim x as
new object" syntax, but many authors included the requirement to always
explicitly destroy objects when no longer needed. I read this so often that
it did become ingrained.
2. Self-documentation: it's easy to see when one is finished using the
object
3. Resource management: releasing large-footprint objects from memory at the
first opportunity can't be bad.
4. Various bugs related to the failure to set objects to nothing have been
documented - these bugs typically involve child objects where the order of
releasing them is important (DAO and ADO), and memory leaks have been
reported, to the point where IIS stops responding.
5. Distrust of the automatic garbage collector (GC) - given the existence of
the various bugs, distrust did develop and combined with the need for
control nentioned in 1, the use of the set x=nothing became ingrained for
many of us.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 27 '06 #4

"Mike Brind" <pa*******@hotmail.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
>
Anthony Jones wrote:
"Lauren the Ravishing" <la******************@yahoo.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi,
>
In ASP, is it absolutely necessary to set an object to Nothing after
being used?
>
set myObj = server.createObject("myDLL.myClass")
call myObj.useClass
set myObj = Nothing <--- can I omit this?
>
I'm dealing with a large number of files with nested includes. There
are many places where I use the object, I want to avoid initializing
the object any more than necessary, and I want to change as few pages
as possible. The simplest way for me to do this is to not set the
object to nothing. Will ASP implicitly remove the object from memory,
or will I have a memory leak?
>
~ L
>
ASP will implicitly call the release method on any interface pointer
currently held by a variable when it passes out of scope. This includes
when the script has completed resulting in the script context being
reset.

Not using set to nothings will not, of itself, introduce a memory leak.
However there is no harm in using set to nothing either and some
developers
consider it good practice (I'm not one of them though).

Why is it considered "good practice" by some?
I think Bob pretty much covered it. The main driver for this whole 'you
should set to nothing' business is bugs in the first versions of ADO. If you
didn't release references to related connection, command and recordset
object in a specific order you could leak memory. Whilst VB(5|6|A|Script)
guarantees to release out of scope references it doesn't guarantee the order
in which it will release them. So the workround to this bug was to release
them yourself in the order needed to avoid the affects of the bug.

This lead to a common myth that VB can't be trusted to release references so
therefore you must do them yourself.
>
--
Mike Brind

Jul 27 '06 #5
Hi,

So is the myth that vbscript can't be trusted in the order it releases
memory, and therefore having the potential to cause a memory leak, which can
bring IIS to a halt, likely to be still be an issue for vbscript running in
an ASP page in Windows 2000 in IIS 5?

If so, what kind of errors what you expect to get as IIS freezes up, and are
there any performance monitors that you could use to detect that it is
happening?

Thanks
Janette


"Anthony Jones" <An*@yadayadayada.comwrote in message
news:ej**************@TK2MSFTNGP04.phx.gbl...
>
"Mike Brind" <pa*******@hotmail.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
>>
Anthony Jones wrote:
"Lauren the Ravishing" <la******************@yahoo.comwrote in
message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi,

In ASP, is it absolutely necessary to set an object to Nothing after
being used?

set myObj = server.createObject("myDLL.myClass")
call myObj.useClass
set myObj = Nothing <--- can I omit this?

I'm dealing with a large number of files with nested includes. There
are many places where I use the object, I want to avoid initializing
the object any more than necessary, and I want to change as few pages
as possible. The simplest way for me to do this is to not set the
object to nothing. Will ASP implicitly remove the object from memory,
or will I have a memory leak?

~ L
ASP will implicitly call the release method on any interface pointer
currently held by a variable when it passes out of scope. This
includes
when the script has completed resulting in the script context being
reset.
>
Not using set to nothings will not, of itself, introduce a memory leak.
However there is no harm in using set to nothing either and some
developers
consider it good practice (I'm not one of them though).

Why is it considered "good practice" by some?

I think Bob pretty much covered it. The main driver for this whole 'you
should set to nothing' business is bugs in the first versions of ADO. If
you
didn't release references to related connection, command and recordset
object in a specific order you could leak memory. Whilst VB(5|6|A|Script)
guarantees to release out of scope references it doesn't guarantee the
order
in which it will release them. So the workround to this bug was to
release
them yourself in the order needed to avoid the affects of the bug.

This lead to a common myth that VB can't be trusted to release references
so
therefore you must do them yourself.
>>
--
Mike Brind


Jul 27 '06 #6

"Janette" <ni**@community.nospamwrote in message
news:OS****************@TK2MSFTNGP06.phx.gbl...
Hi,

So is the myth that vbscript can't be trusted in the order it releases
memory, and therefore having the potential to cause a memory leak, which
can
bring IIS to a halt, likely to be still be an issue for vbscript running
in
an ASP page in Windows 2000 in IIS 5?
Not quite sure what you are saying or asking.

The order in which memory itself is released is not going to cause a leak.
Bugs of this form are invariably found in the components being used by the
ASP pages rather than in ASP/VBScript itself.
If so, what kind of errors what you expect to get as IIS freezes up, and
are
there any performance monitors that you could use to detect that it is
happening?
Set your application protection to high (isolated)
Process -Virtual Bytes (Choose the DLLHOST instance that represents the
application that your having a problem)

If this continues to grow progressively then that would indicate a leaky
app.

This may also be useful:-

Asp Server Pages -Request Executing

If this grows it can show hung Requests once this uses up the available
threads the site will hang.
This is likely caused by using a COM component not designed for use in
unattended mutlithreaded apps.
For example a component which attempt to alert the user to problem via a
message box will just hang the thread.
>
Thanks
Janette


"Anthony Jones" <An*@yadayadayada.comwrote in message
news:ej**************@TK2MSFTNGP04.phx.gbl...

"Mike Brind" <pa*******@hotmail.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
>
Anthony Jones wrote:
"Lauren the Ravishing" <la******************@yahoo.comwrote in
message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi,
>
In ASP, is it absolutely necessary to set an object to Nothing
after
being used?
>
set myObj = server.createObject("myDLL.myClass")
call myObj.useClass
set myObj = Nothing <--- can I omit this?
>
I'm dealing with a large number of files with nested includes.
There
are many places where I use the object, I want to avoid
initializing
the object any more than necessary, and I want to change as few
pages
as possible. The simplest way for me to do this is to not set the
object to nothing. Will ASP implicitly remove the object from
memory,
or will I have a memory leak?
>
~ L
>

ASP will implicitly call the release method on any interface pointer
currently held by a variable when it passes out of scope. This
includes
when the script has completed resulting in the script context being
reset.

Not using set to nothings will not, of itself, introduce a memory
leak.
However there is no harm in using set to nothing either and some
developers
consider it good practice (I'm not one of them though).

Why is it considered "good practice" by some?
I think Bob pretty much covered it. The main driver for this whole 'you
should set to nothing' business is bugs in the first versions of ADO. If
you
didn't release references to related connection, command and recordset
object in a specific order you could leak memory. Whilst
VB(5|6|A|Script)
guarantees to release out of scope references it doesn't guarantee the
order
in which it will release them. So the workround to this bug was to
release
them yourself in the order needed to avoid the affects of the bug.

This lead to a common myth that VB can't be trusted to release
references
so
therefore you must do them yourself.
>
--
Mike Brind


Jul 28 '06 #7
Hi Anthony,

Thanks for the information. One more question, how do you identify what a
dllhost instance is associated with?

Thanks
Janette

"Anthony Jones" <An*@yadayadayada.comwrote in message
news:uN**************@TK2MSFTNGP02.phx.gbl...
>
"Janette" <ni**@community.nospamwrote in message
news:OS****************@TK2MSFTNGP06.phx.gbl...
>Hi,

So is the myth that vbscript can't be trusted in the order it releases
memory, and therefore having the potential to cause a memory leak, which
can
>bring IIS to a halt, likely to be still be an issue for vbscript running
in
>an ASP page in Windows 2000 in IIS 5?

Not quite sure what you are saying or asking.

The order in which memory itself is released is not going to cause a leak.
Bugs of this form are invariably found in the components being used by the
ASP pages rather than in ASP/VBScript itself.
>If so, what kind of errors what you expect to get as IIS freezes up, and
are
>there any performance monitors that you could use to detect that it is
happening?

Set your application protection to high (isolated)
Process -Virtual Bytes (Choose the DLLHOST instance that represents the
application that your having a problem)

If this continues to grow progressively then that would indicate a leaky
app.

This may also be useful:-

Asp Server Pages -Request Executing

If this grows it can show hung Requests once this uses up the available
threads the site will hang.
This is likely caused by using a COM component not designed for use in
unattended mutlithreaded apps.
For example a component which attempt to alert the user to problem via a
message box will just hang the thread.
>>
Thanks
Janette


"Anthony Jones" <An*@yadayadayada.comwrote in message
news:ej**************@TK2MSFTNGP04.phx.gbl...
>
"Mike Brind" <pa*******@hotmail.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...

Anthony Jones wrote:
"Lauren the Ravishing" <la******************@yahoo.comwrote in
message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi,

In ASP, is it absolutely necessary to set an object to Nothing
after
being used?

set myObj = server.createObject("myDLL.myClass")
call myObj.useClass
set myObj = Nothing <--- can I omit this?

I'm dealing with a large number of files with nested includes.
There
are many places where I use the object, I want to avoid
initializing
the object any more than necessary, and I want to change as few
pages
as possible. The simplest way for me to do this is to not set the
object to nothing. Will ASP implicitly remove the object from
memory,
or will I have a memory leak?

~ L
ASP will implicitly call the release method on any interface pointer
currently held by a variable when it passes out of scope. This
includes
when the script has completed resulting in the script context being
reset.

Not using set to nothings will not, of itself, introduce a memory
leak.
However there is no harm in using set to nothing either and some
developers
consider it good practice (I'm not one of them though).

Why is it considered "good practice" by some?

I think Bob pretty much covered it. The main driver for this whole
'you
should set to nothing' business is bugs in the first versions of ADO.
If
you
didn't release references to related connection, command and recordset
object in a specific order you could leak memory. Whilst
VB(5|6|A|Script)
guarantees to release out of scope references it doesn't guarantee the
order
in which it will release them. So the workround to this bug was to
release
them yourself in the order needed to avoid the affects of the bug.

This lead to a common myth that VB can't be trusted to release
references
so
therefore you must do them yourself.


--
Mike Brind



Jul 30 '06 #8

"Janette" <ni**@community.nospamwrote in message
news:O7**************@TK2MSFTNGP06.phx.gbl...
Hi Anthony,

Thanks for the information. One more question, how do you identify what a
dllhost instance is associated with?
It's a bit of a messy. First fire up Component Services from Administrative
tools, expand the tree down to COM+ applications and select that node. In
the tool bar select Status View. The list of COM+ application names should
contain an application called IIS-{...} where the contents of {} is
recognizable to you as your application. (This assumes you have set
application protection to high). The PID column shows the process ID of the
DLLHOST.exe process that is running your web app.

In performance monitor add a counter: Choose the Process performance object,
select the ID Process counter (which is a static value that will match the
PID and select the first DLLHOST in the instances list. ID Process doesn't
match the PID delete the counter and add a counter for the next DLLHOST#1 in
the list and so on until find the one that has a matching PID. Now add the
counters you want to monitor against that instance.
Thanks
Janette

"Anthony Jones" <An*@yadayadayada.comwrote in message
news:uN**************@TK2MSFTNGP02.phx.gbl...

"Janette" <ni**@community.nospamwrote in message
news:OS****************@TK2MSFTNGP06.phx.gbl...
Hi,

So is the myth that vbscript can't be trusted in the order it releases
memory, and therefore having the potential to cause a memory leak,
which
can
bring IIS to a halt, likely to be still be an issue for vbscript
running
in
an ASP page in Windows 2000 in IIS 5?
Not quite sure what you are saying or asking.

The order in which memory itself is released is not going to cause a
leak.
Bugs of this form are invariably found in the components being used by
the
ASP pages rather than in ASP/VBScript itself.
If so, what kind of errors what you expect to get as IIS freezes up,
and
are
there any performance monitors that you could use to detect that it is
happening?
Set your application protection to high (isolated)
Process -Virtual Bytes (Choose the DLLHOST instance that represents
the
application that your having a problem)

If this continues to grow progressively then that would indicate a leaky
app.

This may also be useful:-

Asp Server Pages -Request Executing

If this grows it can show hung Requests once this uses up the available
threads the site will hang.
This is likely caused by using a COM component not designed for use in
unattended mutlithreaded apps.
For example a component which attempt to alert the user to problem via a
message box will just hang the thread.
>
Thanks
Janette


"Anthony Jones" <An*@yadayadayada.comwrote in message
news:ej**************@TK2MSFTNGP04.phx.gbl...

"Mike Brind" <pa*******@hotmail.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...

Anthony Jones wrote:
"Lauren the Ravishing" <la******************@yahoo.comwrote in
message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi,
>
In ASP, is it absolutely necessary to set an object to Nothing
after
being used?
>
set myObj = server.createObject("myDLL.myClass")
call myObj.useClass
set myObj = Nothing <--- can I omit this?
>
I'm dealing with a large number of files with nested includes.
There
are many places where I use the object, I want to avoid
initializing
the object any more than necessary, and I want to change as few
pages
as possible. The simplest way for me to do this is to not set
the
object to nothing. Will ASP implicitly remove the object from
memory,
or will I have a memory leak?
>
~ L
>

ASP will implicitly call the release method on any interface
pointer
currently held by a variable when it passes out of scope. This
includes
when the script has completed resulting in the script context
being
reset.

Not using set to nothings will not, of itself, introduce a memory
leak.
However there is no harm in using set to nothing either and some
developers
consider it good practice (I'm not one of them though).

Why is it considered "good practice" by some?

I think Bob pretty much covered it. The main driver for this whole
'you
should set to nothing' business is bugs in the first versions of ADO.
If
you
didn't release references to related connection, command and
recordset
object in a specific order you could leak memory. Whilst
VB(5|6|A|Script)
guarantees to release out of scope references it doesn't guarantee
the
order
in which it will release them. So the workround to this bug was to
release
them yourself in the order needed to avoid the affects of the bug.

This lead to a common myth that VB can't be trusted to release
references
so
therefore you must do them yourself.


--
Mike Brind






Jul 31 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Paul Rubin | last post by:
I've had this recurring half-baked desire for long enough that I thought I'd post about it, even though I don't have any concrete proposals and the whole idea is fraught with hazards. Basically...
1
by: Earl Eiland | last post by:
I'm running a PyWin program that executes another program using subprocess.Popen(). Unfortunately, this other program isn't well behaved, and frequently terminates without terminating its process....
1
by: Tony | last post by:
Hi, anyone have better information on IIS 5.0 memory behaviour on setting objects to nothing? Connections and recordsets of course should be set to nothing, but should for example XMLNode...
9
by: cppaddict | last post by:
I have a method that uses a fairly large object. The choice is between having a local object in the method or a static member object that the method uses. ------CHOICE 1--------- int...
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
100
by: E. Robert Tisdale | last post by:
What is an object? Where did this term come from? Does it have any relation to the objects in "object oriented programming"?
5
by: Xarky | last post by:
Hi, I am creating a windows form, and when a specified event occurs (button click), I am hiding the windows form and opening a new windows form. When opening the new windows form and closing...
8
by: vvenk | last post by:
Hello: I just wrote my first ASP.Net application. It worked fine on my machine and when I put into production, the ASP.Net process reaches 50% quite fast and then the system does not work...
2
by: Fish | last post by:
I have been researching the correct way to organize my solution so that it makes best use of VB.NET inherent ability to manage resources such as objects. My solution contains 2 projects and the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.