开发者

What happens when NOT closing recordsets in classic asp?

In legacy applications at work, i see not开发者_开发百科 closed recordsets scattered on lots of pages.

  • What consequences does this have?
  • Does the connection close automatically?
  • Are resources released at the end of every request?

Update:

  • Another question related to this problem i think

txn!


  • What consequences does this have?

Resources don't get freed up as quickly, and depending on the rest of the code performance will suffer.

  • Does the connection close automatically?
  • Are resources released at the end of every request?

At the end of page execution, all connections are terminated and all resources released. Some people figure that since this happens, there is no need to worry about explicitly closing connections and/or releasing resources.

All things being equal, reliance on this is not something that is encouraged as you never know how things will play out in heavy traffic - which is why all the good tutorials/instructors will tell you to open only when you need, and release as soon as you are done.


Close recordset does not close the connection

http://www.devguru.com/technologies/ado/QuickRef/recordset_close.html

You should always close connections as soon as possible, to release them back into the connection pool.

A system that leaks connections will slow down and gradually grid to a halt.


If you don't close it you will have memory leaks, which can quickly eat up your resources. IIS will eventually clean resources for you, but it's not very reliable. It's safer and more reliable to explicitly close your recordset and then set it to nothing to free up resources. Also be sure close your connection and set it to nothing as well.


I actively maintain dozens of Classic ASP websites/intranets/extranets/systems.

The rules of thumb are :

  • Declare, assign and open variables and object instances lately
  • Use the .close() method (on recordsets)

Then, for ANY object instance, us the following to free the memory :

  • Set variableABC = Nothing'It will break the pointer between the variable and the object instance, but it will not free the memory
  • variableABC = Empty 'It will effectively free the memory. This last one also applies to all kind of variables, as VBScript/ASP variables are untyped. So a String, a Long, a Currency, or an Array can (and should) be Freed up this way along your script (applies only to decent sized vars. It would be useless to free a variable containing "abc", unless you have millions of them in your script).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜