/// <summary> /// Load from memory buffer 10000 times. /// /// It runs in a fairly steady 60MB of ram for me. Watching the output, you see /// stuff like: /// /// memory processing <NetVips.Image 4120x2747 uchar, 3 bands, srgb> /// 24 vips objects known to net-vips /// memory processing <NetVips.Image 4120x2747 uchar, 3 bands, srgb> /// 21 vips objects known to net-vips /// memory processing <NetVips.Image 4120x2747 uchar, 3 bands, srgb> /// 23 vips objects known to net-vips /// memory processing <NetVips.Image 4120x2747 uchar, 3 bands, srgb> /// 16 vips objects known to net-vips /// memory processing <NetVips.Image 4120x2747 uchar, 3 bands, srgb> /// 7 vips objects known to net-vips /// memory processing <NetVips.Image 4120x2747 uchar, 3 bands, srgb> /// 7 vips objects known to net-vips /// memory processing <NetVips.Image 4120x2747 uchar, 3 bands, srgb> /// 9 vips objects known to net-vips /// memory processing <NetVips.Image 4120x2747 uchar, 3 bands, srgb> /// 4 vips objects known to net-vips /// memory processing <NetVips.Image 4120x2747 uchar, 3 bands, srgb> /// /// So when around 25 vips objects are alive, the C# gc runs and they all get /// flushed. /// /// If you want it to run in less ram than that, you'll need to expose the GC and /// trigger it manually every so often. /// </summary> /// <param name="args">Command-line arguments.</param> /// <returns>Result.</returns> public string Execute(string[] args) { NetVips.LeakSet(true); NetVips.CacheSetMax(0); var imageBytes = File.ReadAllBytes(Filename); for (var i = 0; i < 10000; i++) { using var img = Image.NewFromBuffer(imageBytes); Console.WriteLine($"memory processing {img}"); // uncomment this line together with the `NObjects` variable in GObject // Console.WriteLine($"{GObject.NObjects} vips objects known to net-vips"); } return("All done!"); }