473,785 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP - Terminating objects in memory

Hi,

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

set myObj = server.createOb ject("myDLL.myC lass")
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 2055

"Lauren the Ravishing" <la************ ******@yahoo.co mwrote in message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
Hi,

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

set myObj = server.createOb ject("myDLL.myC lass")
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.co mwrote in message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
Hi,

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

set myObj = server.createOb ject("myDLL.myC lass")
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*******@hotm ail.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...
>
Anthony Jones wrote:
"Lauren the Ravishing" <la************ ******@yahoo.co mwrote in message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
Hi,
>
In ASP, is it absolutely necessary to set an object to Nothing after
being used?
>
set myObj = server.createOb ject("myDLL.myC lass")
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*@yadayadaya da.comwrote in message
news:ej******** ******@TK2MSFTN GP04.phx.gbl...
>
"Mike Brind" <pa*******@hotm ail.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...
>>
Anthony Jones wrote:
"Lauren the Ravishing" <la************ ******@yahoo.co mwrote in
message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
Hi,

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

set myObj = server.createOb ject("myDLL.myC lass")
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******** ********@TK2MSF TNGP06.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*@yadayadaya da.comwrote in message
news:ej******** ******@TK2MSFTN GP04.phx.gbl...

"Mike Brind" <pa*******@hotm ail.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...
>
Anthony Jones wrote:
"Lauren the Ravishing" <la************ ******@yahoo.co mwrote in
message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
Hi,
>
In ASP, is it absolutely necessary to set an object to Nothing
after
being used?
>
set myObj = server.createOb ject("myDLL.myC lass")
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*@yadayadaya da.comwrote in message
news:uN******** ******@TK2MSFTN GP02.phx.gbl...
>
"Janette" <ni**@community .nospamwrote in message
news:OS******** ********@TK2MSF TNGP06.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*@yadayadaya da.comwrote in message
news:ej******* *******@TK2MSFT NGP04.phx.gbl.. .
>
"Mike Brind" <pa*******@hotm ail.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...

Anthony Jones wrote:
"Lauren the Ravishing" <la************ ******@yahoo.co mwrote in
message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
Hi,

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

set myObj = server.createOb ject("myDLL.myC lass")
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******** ******@TK2MSFTN GP06.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*@yadayadaya da.comwrote in message
news:uN******** ******@TK2MSFTN GP02.phx.gbl...

"Janette" <ni**@community .nospamwrote in message
news:OS******** ********@TK2MSF TNGP06.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*@yadayadaya da.comwrote in message
news:ej******** ******@TK2MSFTN GP04.phx.gbl...

"Mike Brind" <pa*******@hotm ail.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...

Anthony Jones wrote:
"Lauren the Ravishing" <la************ ******@yahoo.co mwrote in
message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
Hi,
>
In ASP, is it absolutely necessary to set an object to Nothing
after
being used?
>
set myObj = server.createOb ject("myDLL.myC lass")
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
3319
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 I wish there was a way to have persistent in-memory objects in a Python app, maybe a multi-process one. So you could have a persistent dictionary d, and if you say d = Frob(foo=9, bar=23) that creates a Frob instance and stores it in d. Then if...
1
2082
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. After this happens enough times, all my memory is tied up, and the machine crashes. Using subprocess.poll(), I can keep my program from hanging, by timing out the process, and starting anew. This still leaves the previous process hogging...
1
5449
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 object be set to nothing? Thanks, Tony
9
2529
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 MyClass::myMethod(int param) { MyBigObject o(); //initialize o based on param //do calculations with o
6
2581
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 "SEGV" when run (presumably - attempt to delete deleted memory. Please take a look and see if you can notice any mistakes I'm making. Basically, I want to store classes of my objects in a vector. I also have three further questions:
100
5302
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
6586
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 it, the main windows form would still be running in the background and never terminating. How can I terminate the old window form from the new created window. I hope someone out there understands my problem.
8
1952
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 anymore until I kill that process. Obviously, this is not acceptable. Looking back, I do not destroy any objects in my form. Would that be the reasn why the application breaks down?
2
1628
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 main problem is that the mem usage continues to grow until the Service stops responding. I have received advice to: "create those objects at a class level; instantiate them when the service starts, and dispose of them when the service ends. Then...
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9485
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8986
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.