ScriptService执行进餐记忆

时间:2019-05-31 06:06:01

标签: c# google-api mono

当我对ScriptService运行请求运行Execute时,它将占用一些内存,但无法释放它。通过在Raspberry Pi上的monodevelop上运行进行测试,显示内存以惊人的速度增长,最终将使程序崩溃。 GC.Collect试图回收该内存。对我在做什么错有任何见解吗?

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;
}

1 个答案:

答案 0 :(得分:0)

我已解决此问题,安装Mono Preview v6.0.0.277已解决了此问题,现在无需手动调用GC.Collect()即可正确释放内存。

Related issue which led to the solution