首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ScriptService执行吞噬内存

ScriptService执行吞噬内存
EN

Stack Overflow用户
提问于 2019-05-31 14:06:01
回答 1查看 36关注 0票数 0

当我对ScriptService运行请求运行Execute时,它会占用一些内存,但无法将其释放。通过在Raspberry Pi上运行monodevelop进行测试,显示内存以惊人的速度上升,最终将使程序崩溃。GC.Collect就是为了重新获得这个内存的尝试。对我做错了什么有什么见解吗?

代码语言:javascript
复制
public MainWindow() : base(Gtk.WindowType.Toplevel)
{
    Build();

    while (true)
    {
        getDashRow();

        Thread.Sleep(1000);
        Console.WriteLine("Total available memory before collection: {0:N0}", System.GC.GetTotalMemory(false));

        System.GC.Collect();

        Console.WriteLine("Total available memory collection: {0:N0}", System.GC.GetTotalMemory(true));
    }
 }

 private int getDashRow()
 {
    ScriptsResource.RunRequest runreq;
    DriveService driveservice;
    ExecutionRequest exrequest;

    Console.WriteLine("getDashRow");
    int retval = 0;

    exrequest = new ExecutionRequest();
    exrequest.Function = "getMacRow";
    IList<object> parameters = new List<object>();
    parameters.Add(spreadsheetname);
    exrequest.Parameters = parameters;
    exrequest.DevMode = false;

    try
    {
        // run a Google Apps Script function on the online sheet to find number of rows (more efficient)
        runreq = scriptservice.Scripts.Run(exrequest, dashscriptid);

        // following line consumes the memory
        Operation op = runreq.Execute();

        retval = Convert.ToInt16(op.Response["result"]);
        parameters = null;
        exrequest = null;
        op = null;
    }
    catch (Exception ex)
    {
        Console.WriteLine("getDashRow: " + ex.Message);
    }

    return retval;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-06 11:31:24

我解决了这个问题,安装Mono Preview v6.0.0.277已经解决了这个问题,内存现在可以正确释放,而不需要手动调用GC.Collect()。

Related issue which led to the solution

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56389489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档