Excel加载项:Office.context.document.setSelectedDataAsync(...)导致Internet Explorer内存不断攀升,最终导致加载项崩溃 [英] Excel Add-In: Office.context.document.setSelectedDataAsync(...) causes Internet Explorer memory to keep climbing, eventually the add-in crashes

查看:126
本文介绍了Excel加载项:Office.context.document.setSelectedDataAsync(...)导致Internet Explorer内存不断攀升,最终导致加载项崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有些东西可以用来释放内存?

Is there something devs are supposed to do to free the memory?

使用Office.context.document。当IE进程达到约1.5MB内存时,setSelectedDataAsync(...)不会释放内存,最终Excel加载项崩溃。

Using Office.context.document.setSelectedDataAsync(...) does not release memory and eventually the Excel Add-In crashes when the IE process reaches about 1.5MB memory.

要在Excel中重现以下代码-in 并在任务管理器中查看iexplore.exe。创建4张表,然后向每个表添加数据。 在我的开发PC上尝试在第四张纸上添加数据时,加载项就会挂起,而任务
管理器中的iexplore.exe固定在大约1.5MB(有时更低)。

To reproduce us the code below in an Excel Add-in and watch iexplore.exe in Task Manager. Create 4 sheets and then add data to each.  On my dev PC when trying to add the data on the fourth sheet the Add-in just hangs and iexplore.exe in Task Manager is pinned at about 1.5MB (sometimes lower).

谢谢,

Jim

<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8" />
   <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
   <title></title>
   <script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
 
   <link href="../../Content/Office.css" rel="stylesheet" type="text/css"/>
 
   <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
   
   <script>
      (function () {
 
         "use strict";
 
         var bindingId = "TestBindingId";
         var msg = "";
 
         // The initialize function must be run each time a new page is loaded
         Office.initialize = function (reason) {
            $(document).ready(function () {
 
               $('#create-table-at-selection').click(createTableAtSelection);
 
               
               $('#clear-msg').click(clearMsg);
            });
         };
 
 
         function createTableAtSelection()
         {
            var tableData = new Office.TableData();
            //tableData.headers = [['header1']];
 
            var rows = [], cells = [];
 
            var formatColor = { fontColor: "blue" };
            var formats = [];
            var formatCells = {};
         
            for (var r = 0; r < 10000; r++)
            {
               cells = [];
               
               for (var c = 0; c < 20; c++)
               {
                  cells.push("data");
 
                  formatCells = {};
                  formatCells.cells = {};
                  formatCells.format = {};
 
                  formatCells.cells.row = r;
                  formatCells.cells.column = c;
                  formatCells.format = formatColor;
                  formats.push(formatCells);
               }
 
               rows.push(cells);
            }
 
            
            var tableOptions = { headerRow: true, filterButton: true, bandedRows: false, style: "none" };
 
            var options = {
               coercionType: Office.CoercionType.Table,
               tableOptions: tableOptions,
               cellFormat: formats
            };
 
            tableData.rows = rows;
            Office.context.document.setSelectedDataAsync(tableData, options,
            function (asyncResult)
            {
               write(asyncResult.status);
               formats.length = 0;
               rows.length = 0;
               tableData.rows.length = 0;
            });
         }
 
 
 
         function write(message) {
            msg += message + "<br/><br/>";
            $('#message').html(msg);
         }
 
         function clearMsg() {
            msg = "";
            $('#message').html("");
         }
 
      })();
 
   </script>
 
</head>
<body>
   <div id="content-main">
 
      <div style="padding10px">
         <h1>Test Delete</h1>
 
         <br />
         <button id="create-table-at-selection">Create Table at Selection</button>
 
 
 
         <br />
         <br />
         <button id="clear-msg">Clear Message</button>
 
         <br /><br />
         Status
         <div id="message" style="background#e0e0e0padding15px;"></div>
      </div>
   </div>
</body>
</html>

推荐答案

嗨Jim,

我用您的描述进行了测试,我可以重现您的问题,我拆分变量对象和setSelectedDataAsync,看起来攀爬内存与setSelectedDataAsync相关,我发现没有什么可以释放这个内存。

I made a test with your description, and I could reproduce your issue, I split the variable object and setSelectedDataAsync, it seems the climbing memory is related with setSelectedDataAsync, I found nothing to release this memory.

基于
Office的资源限制和性能优化加载项
,似乎没有更好的方法来解决此问题。

Based on Resource limits and performance optimization for Office Add-ins, it seems there is no better way to workaround this issue.

如果任何内容或任务窗格加载项超过CPU核心上的前面的阈值o r内存使用情况或崩溃的容差限制,相应的主机应用程序会为用户显示警告。此时,用户可以执行以下操作之一:

If any content or task pane add-in exceeds the preceding thresholds on CPU core or memory usage, or tolerance limit for crashes, the corresponding host application displays a warning for the user. At this point, the user can do one of the following:



  • 重新启动加载项。

  • Restart the add-in.

取消有关超过该阈值的进一步警报。理想情况下,用户应该从文档中删除加载项;继续加载项会冒更进一步的性能和稳定性问题。

Cancel further alerts about exceeding that threshold. Ideally, the user should then delete the add-in from the document; continuing the add-in would risk further performance and stability issues.

最好的问候,

爱德华


这篇关于Excel加载项:Office.context.document.setSelectedDataAsync(...)导致Internet Explorer内存不断攀升,最终导致加载项崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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