ScriptService 执行吃内存

ScriptService execute eating memory

当我 运行 在 ScriptService 运行 请求上执行时,它占用了一些内存并且无法释放它。 运行ning 在 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;
}

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

Related issue which led to the solution