【问题标题】:Byte array of 13 MB gives out of memory exception in asp.net13 MB 的字节数组在 asp.net 中出现内存不足异常
【发布时间】:2013-11-25 13:29:53
【问题描述】:

我有一个应用程序,它通过将 HTML 转换为字节数组来将其转换为 PDF。但是,我观察到,由于我的字节数组大小超过 13 MB,它给出:OutOfMemoryException

据我所知,我最多可以为 32 位机器中的变量分配 2GB 的空间,并且我还处理其他使用的变量。那么理想情况下我不应该记忆力不足,不是吗?

另外,当我最初声明字节数组大小为 1 gb 时,它不会给出错误,但是当它被分配数据时,数组的大小 resized strong> 根据数据的大小,当它超过 13 gb 时,它会崩溃吗?

为什么数组调整大小,而我已经声明它可以容纳 1gb 内存?

**编辑:

以下是导致错误的代码行:

objpage.Layout(html1); //html1 holds my huge full HTML which is of approx 5.5k word doc                 //pages 

pdfBuffer = new byte[1073741824]; //declare the byte array of size 1 gb,no error here.  //Note, i just added this declaration, this is not the cause of the problem, it wasn't //initially there 

pdfBuffer = document1.WriteToMemory(); //This is my API method of the third party tool  //which converts pdf document object to byte array. This line is where the error comes (my //array of 1 GB gets resized to 13+ MB) 

【问题讨论】:

  • 什么样的异常?
  • 它给出“OutOfMemoryException”
  • 向我们展示您的一些代码。很难在没有看到任何东西的情况下进行调试。
  • Web 应用程序通常限制为 300 MB。如果增加数组,它需要分配一个新副本,所以不能将数组增加到超过 150 MB。由于应用程序已经在为其他事情使用一些内存,它甚至更少。查看获得异常的代码会有所帮助。
  • 很难将代码放在这里,因为它很大,而且代码块没有任何用处,因为我的 HTML 字符串包含大约 5500 个单词的文件页面,我使用第三个将其转换为 PDF 文档派对 (HIQPDF) 工具。然后,此工具中的一种方法将整个文档转换为字节数组,如下所示:

标签: asp.net arrays memory byte allocation


【解决方案1】:

试试这个

 <system.web>
 <httpRuntime maxRequestLength="2000000000" executionTimeout="99999999"/>
 <pages validateRequest="false"/>
 </system.web>

这里根据你的应用增加值

【讨论】:

    【解决方案2】:

    我以前也遇到过类似的问题,

    我尝试编辑 webconfig 文件中的一些代码,这对我有用。

    <system.web>
    <httpRuntime executionTimeout="100" maxRequestLength="819200" useFullyQualifiedRedirectUrl="false"/>
    </system.web>
    

    您是否尝试过编辑执行超时和最大请求​​长度?尝试更改它并给它一个更高的数字。

    【讨论】:

    • 感谢您的建议,但我目前的参数已经持有更高的价值。以下是我当前的 web.config 条目:
    • 您需要为 IIS 和应用程序设置最大值。
    • 我的代码也不能在我的本地机器上运行,所以现在没有 IIS 设置的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2014-06-09
    • 1970-01-01
    • 2011-11-15
    • 2016-02-11
    • 2014-03-28
    相关资源
    最近更新 更多