devxlogo

ASP components aren’t released by setting their references to Nothing

ASP components aren’t released by setting their references to Nothing

If you instantiate an ActiveX component from an ASP script under IIS 4 and previous versions, using the Server.CreateObject command, you might believe that the object is deallocated as soon as you set its reference to Nothing – this is how all COM components work, right?

The problem with ASP components is that IIS keeps a private reference to the objects you instantiate from ASP scripts, and this reference is set to Nothing only after the entire ASP script has completed its execution. This extra reference is necessary to invoke the OnEndPage method when the ASP script has completed its execution.

In most cases this detail doesn’t cause any problem, but sometimes it can be the source of very subtle bugs. For example, if your component contains some code in the Class_Terminate event, this code will be executed at the wrong moment. For example, if the code read a Session or Application variable, it can retrreive the wrong values. Worse, if the code sends HTML output through the Response ASP object, it won’t work at all, because when the Class_Terminate event fires, the page has already been sent to the client browser.

Note that IIS5 deals with COM components in a smarter way: if the component doesn’t expose an OnEndPage, when the ASP script sets the last reference to it is to Nothing the object is immediately destroyed.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist