I have been doing some investigation into memory use of our Rhino runtime when run from the command line and came across what seems to be a memory leak.
Grasshopper models that contain point params do not seem to clean up (part of) their memory footprint.
I am using Rhino 7.37.24107.15001
on Windows 11 Pro, version 22H2 (build: 22621.4317)
I run the following sequence in a loop:
var io = new Grasshopper.Kernel.GH_DocumentIO();
io.Open(modelPath)
using (var doc = io.Document)
{
Console.WriteLine($"(Document loaded. TotalMemory: {MB(GC.GetTotalMemory(false))})");
}
GC.Collect();
GC.WaitForPendingFinalizers();
var currentMemory = GC.GetTotalMemory(true);
var diff = currentMemory - previousMemory;
Console.WriteLine($"Completed. TotalMemory: {MB(currentMemory)}, Diff: {KB(diff)}");
previousMemory = currentMemory;
Full runnable project for repro with test definitions in the zip attached: SampleRhino.zip
When the model contains, say numbersliders, panels, surface components memory of the document is cleaned up as expected. However when opening and disposing a document with point params about 1KB per param remains for each param after dispose:
Loading RhinoCommon version 7.37.24107.15001
Running main loop for model 'definitions\points.gh', press CTRL+C to quit anytime. TotalMemory: 3MB
Completed. TotalMemory: 16MB, Diff: 13453KB
Completed. TotalMemory: 16MB, Diff: 116KB
Completed. TotalMemory: 16MB, Diff: 117KB
Completed. TotalMemory: 16MB, Diff: 115KB
Completed. TotalMemory: 16MB, Diff: 125KB
Completed. TotalMemory: 17MB, Diff: 117KB
Completed. TotalMemory: 17MB, Diff: 113KB
Completed. TotalMemory: 17MB, Diff: 116KB
Completed. TotalMemory: 17MB, Diff: 113KB
Completed. TotalMemory: 17MB, Diff: 131KB
Completed. TotalMemory: 17MB, Diff: 122KB
Completed. TotalMemory: 17MB, Diff: 121KB
Completed. TotalMemory: 17MB, Diff: 109KB
Completed. TotalMemory: 18MB, Diff: 128KB
Completed. TotalMemory: 18MB, Diff: 88KB
Completed. TotalMemory: 18MB, Diff: 115KB
Completed. TotalMemory: 18MB, Diff: 129KB
Completed. TotalMemory: 18MB, Diff: 114KB
Completed. TotalMemory: 18MB, Diff: 104KB
Completed. TotalMemory: 18MB, Diff: 114KB
Completed. TotalMemory: 18MB, Diff: 131KB
Completed. TotalMemory: 18MB, Diff: 115KB
Completed. TotalMemory: 19MB, Diff: 116KB
Completed. TotalMemory: 19MB, Diff: 116KB
Completed. TotalMemory: 19MB, Diff: 129KB
Completed. TotalMemory: 19MB, Diff: 100KB
Completed. TotalMemory: 19MB, Diff: 115KB
Completed. TotalMemory: 19MB, Diff: 115KB
Completed. TotalMemory: 19MB, Diff: 115KB
Completed. TotalMemory: 19MB, Diff: 115KB
Completed. TotalMemory: 19MB, Diff: 115KB
Completed. TotalMemory: 20MB, Diff: 115KB
Completed. TotalMemory: 20MB, Diff: 115KB
Interrupted, stopping app ..
Completed. TotalMemory: 20MB, Diff: 115KB
Done
This in the attached project the points.gh
definition contains 100 points.
When looking at the memory profile at each iteration, what stands out to me is that CentralSettings.PreviewGumballsChanged Event seems to be keeping the point params in memory through its attributes:
Question
Do I need to do anything extra to the document to dispose point parameters?
(See also GH issue in compute.rhino3d repo: GH_Document dispose does not clean up Param_Point memory footprint · Issue #698 · mcneel/compute.rhino3d · GitHub)