VBScript 内存不足错误 [英] VBScript Out Of Memory Error

查看:43
本文介绍了VBScript 内存不足错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由第三方公司构建的经典 ASP CRM.目前,我可以访问源代码并能够进行所需的任何更改.

I have a classic ASP CRM that was built by a third party company. Currently, I have access to the source code and am able to make any changes required.

在一天中随机出现,通常是在用户长时间使用之后,我的大多数页面开始出现内存不足错误.

Randomly throughout the day, usually after some prolonged usage by users, most of my pages start getting an Out of Memory error.

应用程序的构建方式是所有页面和脚本都从 Global.asp 文件中提取核心功能.在该文件中也嵌入了其他全局文件,但出现的错误显示

The way that the application is built, is all the pages and scripts pull core functions from a Global.asp file. In that file are embeds to other global files as well, but the error presented shows

内存不足

WhateverScriptYouTriedToRun.asp 第 0 行

WhateverScriptYouTriedToRun.asp Line 0

第 0 行是 global.asp 文件的包含.一旦发生错误,在未指定的时间量后,错误发生会消退一段时间,但随后又开始再次发生.关于应用程序的编写方式,它使用的功能,以及我已经完成的诊断" - 它似乎是一个常用的功能,它会保留诸如记录集或类似性质的数据,然后不正确地释放它.然后其他用户尝试使用相同的功能,最终它只是填满导致错误.我有效清除错误的唯一方法是实际重新启动 IIS、回收应用程序池并重新启动 SQL Server 服务.

Line 0 is the include for the global.asp file. Once the error occurs, after an unspecified amount of time the error occurence subsides for some time but then begins to reoccur again. With how the application is written, and the functions it uses, and the "diagnostics" I've already done - it seems to be a common used function that is withholding data such as recordset or something of that nature and then not releasing it properly. Other users then try to use the same function and eventually it just fills up causing the error. The only way for me to effectively clear the error is to actually restart IIS, Recycle the App Pool, and Restart the SQL Server Services.

不用说,我自己和我的用户都在生气....

Needless to say, myself and my users are getting annoyed....

由于显示的实际错误消息是第 0 行,我无法查明错误 - 但从那里我不知道它可能在 20K 行代码中的哪个位置挂起.关于如何隔离或至少将我指向正确的方向以开始清理这个问题的任何想法或想法?有没有办法增加 VBScript 的内存"大小?我知道有一个限制,但它是否设置为...512K,您可以将其增加到 1GB?

I can't pinpoint the error due to the actual error message presented being Line 0 - but from there I have no idea where in the 20K lines of code it could be hanging up. Any thoughts or ideas on how to isolate or at least point me in the right direction to begin clearing this up? Is there a way for me to increase "memory" size for VBScript? I know there is a limitation but is it set at say...512K and you can increase it to 1GB?

以下是我尝试过的事情:

Here are things I have tried:

  1. 将 SQL 内联语句移除到视图中
  2. 检查数百个脚本并确保每个 OpenConnection &OpenRecordSet 后跟一个适当的 Close.
  3. 遍历全局文件并注释掉任何大型 SQL 语句,例如 ApplicationLog(将执行的查询写入表的函数).
  4. 一些较小的脚本编辑.

推荐答案

常见内存泄漏

你说你正在关闭所有记录集和连接,这很好.

You say you are closing all recordsets and connections which is good.

但是你是在删除对象吗?

But are you deleting objects?

例如:

Set adoCon = new
Set rsCommon = new

'Do query stuff

'You do this:
rsCommon.close
adocon.close

'But do you do this?
Set adoCon = nothing
Set rsCommon = nothing

经典 ASP 中没有垃圾收集,因此任何未销毁的对象都将保留在内存中.

No garbage collection in classic ASP, so any objects not destroyed will remain in memory.

此外,请确保您的关闭/无操作在每个分支中运行.例如:

Also, ensure your closes/nothings are run in every branch. For example:

adocon.open
rscommon.open etc

'Sql query
myData = rscommon("condition")

if(myData) then
  response.write("ok")
else
  response.redirect("error.asp")
end if

'close
rsCommon.close
adocon.close
Set adoCon = nothing
Set rsCommon = nothing

在重定向之前没有任何东西被关闭/销毁,因此它只会在某些时候清空内存,因为并非所有逻辑分支都会导致正确的内存清除.

Nothing is closed/destroyed before the redirect so it will only empty memory some of the time as not all branches of logic lead to the proper memory clearance.

更好的设计

不幸的是,这听起来网站设计得不好.我总是将我的经典 ASP 构建为:

Also unfortunately it sounds like the website wasn't designed well. I always structure my classic ASP as:

<%
    Option Explicit

    'Declare all vars
    Dim this
    Dim that

    'Open connections
    Set adoCon...
    adocon.open()

    'Fetch required data
    rscommon.open strSQL, adoCon
        this = rsCommon.getRows()
    rsCommon.close

    'Fetch something else
    rscommon.open strSQL, adoCon
        that = rsCommon.getRows()
    rsCommon.close

    'Close connections and drop objects
    adoCon.close
    set adoCon = nothing
    set rscommon = nothing

    'Process redirects
    if(condition) then
        response.redirect(url)
    end if
%>
<html>
<body>

<%
    'Use data
    for(i = 0 to ubound(this,2)
        response.write(this(0, i) & " " & this(1, i) & "<br />")
    next
%>

</body>

</html>

希望这能有所帮助.

这篇关于VBScript 内存不足错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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