Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB6,VBS,IIS4,IIS5
Expertise: Advanced
May 13, 2000

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.

Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date