记录集对象 [英] Recordset object

查看:84
本文介绍了记录集对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么检索后将记录集对象设置为空?其背后的技术思想是什么?

例如.

Why do we set a recordset object to nothing after retrieving? What is the technical idea behind that?

eg.

dim  rsTemp

set rsTemp = Server.CreateObject("ADODB.recordset")
' after that I retrieve some data
rsTemp.Open "select * from Rates" blah, blah


然后我看到这样的东西:


then I see something like this:

set rsTemp = nothing


推荐答案

通常的原因是RecordSet占用了计算机上的资源-内存,可能的时钟周期等.因此,在达到其目的后立即处置它是一个好主意,以便可以对其进行垃圾收集并释放其资源.

这适用于您的代码创建的任何对象.如果对象实现IDisposable,则还应该调用其Dispose方法.

在没有看到代码示例来自的上下文的情况下,无法判断是否必须分配给nothing,但是始终最好尽快进行操作,而不是等待框架完成操作
The usual reason for this is that the RecordSet takes up resources on the computer - memory, possibly clock cycles etc. so it is a good idea to dispose of it as soon as it has served its purpose so that it can be garbage collected and its resources freed up.

This applies to any object that your code creates. If the object implements IDisposable, you should also call its Dispose method.

Without seeing the context that your code example comes from it is not possible to tell if the assignment to nothing is necessary, but it is always a good idea to do it as soon as possible, rather than waiting for the framework to do it for you.


之所以这样做,是因为这些对象并非总是像过去那样被破坏.通常,当COM对象超出范围且未设置引用时,它们会自动释放.对于某些COM对象,过去这有点问题.对于某些人来说是必要的,而对于其他人(或其他环境)则没有.但是为了简单地确保它确实起作用,添加了这些行以将它们专门设置为空.记录集也需要顺便关闭.同样,如果与数据库的连接仍处于打开状态,并且该对象仍具有对打开的记录集的引用,那么很可能在关闭连接之前不会释放它.

据我所知,对于ASP来说,这并不重要,因为在处理请求之后,所有内容(可能是会话数据除外)都会被释放.

祝你好运!
The reason for that is because those objects weren''t always destroyed like they should in past times. COM objects are normally automatically released when they get out of scope and have no references set to them. For some COM objects this was somewhat problematic in the past. For some it was necessary and for others (or other environments) it wasn''t. But to simply make sure that it does, those lines where added to set them to nothing specifically. The recordset would need to be closed as well by the way. Also, if the connection to the database is still open and that object still has a reference to the opened recordset, then it is of course very likely that it isn''t released until the connection is closed.

As what I know it shouldn''t really matter for ASP because after the request is handled, everything (except maybe session data) is released.

Good luck!


这篇关于记录集对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆