cart: empty [ Login ]

Facing memory leak issue while using BoundsCalculator class

1 
Sachin Tripathi
2/7/2020 5:17 AM
Hi Wout, We are facing memory leak issue while using BoundCalculator class to get model object boundaries. Every time when we are executing code below to calculate model boundaries it increases memory utilization by ~1GB. var cal = new BoundsCalculator(); cal.GetBounds(pageModel, pageModel.Entities); Note: pageModel in code, we are having ArchE size of JPEG image as a background. Sometimes memory utilization is going beyond 5GB for single user(see attached report) and we are getting exception below: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.Buffers.ConfigurableArrayPool`1.Rent(Int32 minimumLength) at SixLabors.Memory.ArrayPoolMemoryAllocator.Allocate[T](Int32 length, AllocationOptions options) at SixLabors.ImageSharp.Memory.MemoryAllocatorExtensions.Allocate2D[T](MemoryAllocator memoryAllocator, Int32 width, Int32 height, AllocationOptions options) at SixLabors.ImageSharp.Image.CreateUninitialized[TPixel](Configuration configuration, Int32 width, Int32 height, ImageMetaData metadata) at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.PostProcessIntoImage[TPixel]() at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.Decode[TPixel](Stream stream) at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoder.Decode[TPixel](Configuration configuration, Stream stream) at SixLabors.ImageSharp.Image.Decode[TPixel](Stream stream, Configuration config) at SixLabors.ImageSharp.Image.<>c__DisplayClass55_0`1.<Load>b__0(Stream s) at SixLabors.ImageSharp.Image.WithSeekableStream[T](Configuration config, Stream stream, Func`2 action) at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, Stream stream, IImageFormat& format) at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, String path) at WW.Drawing.NetCoreBitmap.LoadBitmap(String filename, String modelFilename, Int32 downloadTimeoutMs) at WW.Cad.Model.Objects.DxfImageDef.get_Bitmap() at WW.Cad.Model.Entities.DxfRasterImage.get_() at WW.Cad.Model.Entities.DxfRasterImage.get_() at WW.Cad.Model.Entities.DxfRasterImage.(DrawContext ) at WW.Cad.Model.Entities.DxfRasterImage.DrawInternal(Wireframe context, IWireframeGraphicsFactory graphicsFactory) at WW.Cad.Drawing.BoundsCalculator.GetBounds(DxfModel model, IEnumerable`1 entities, Matrix4D modelTransform) at WW.Cad.Drawing.BoundsCalculator.GetBounds(DxfModel model, IEnumerable`1 entities) So, do we have any other way to calculate model boundaries? Or any solution for this issue? In case any sample line of code required I'll send in separate email. Thanks, Sachin
MemoryLeakIssue_MemoryMgmnt.png
Wout
2/7/2020 3:14 PM
Hi, I don't see any evidence of a memory leak when I test locally. Here is my test program and test data is attached.
C# Code:
Console.WriteLine(GC.GetTotalMemory(true)); for (int i = 0; i < 100; ++i) { var model = CadReader.Read(@"ImageTestR18.dwg"); BoundsCalculator boundsCalculator = new BoundsCalculator(); boundsCalculator.GetBounds(model); model.Dispose(); Console.WriteLine($"{i}: {GC.GetTotalMemory(true)}"); }
Program output: 270032 0: 540504 1: 540640 2: 540640 3: 540640 4: 540640 5: 540640 6: 540640 7: 540640 8: 540640 9: 540640 10: 540640 11: 540640 12: 540640 13: 540640 14: 540640 15: 540640 16: 540640 17: 540640 18: 540640 19: 540640 20: 540640 21: 540640 22: 540640 23: 540640 24: 540640 25: 540640 26: 540640 27: 540640 28: 540640 29: 540640 30: 540640 31: 540640 32: 540640 33: 540640 34: 540640 35: 540640 36: 540640 37: 540640 38: 540640 39: 540640 40: 540640 41: 540640 42: 540640 43: 540640 44: 540640 45: 540640 46: 540640 47: 540640 48: 540640 49: 540640 50: 540640 51: 540640 52: 540640 53: 540640 54: 540640 55: 540640 56: 540640 57: 540640 58: 540640 59: 540640 60: 540640 61: 540640 62: 540640 63: 540640 64: 540640 65: 540640 66: 540640 67: 540640 68: 540640 69: 540640 70: 540640 71: 540640 72: 540640 73: 540640 74: 540640 75: 540640 76: 540640 77: 540640 78: 540640 79: 540640 80: 540640 81: 540640 82: 540640 83: 540640 84: 540640 85: 540640 86: 540640 87: 540640 88: 540640 89: 540640 90: 540640 91: 540640 92: 540640 93: 540640 94: 540640 95: 540640 96: 540640 97: 540640 98: 540640 99: 540640 - Wout
image.png
1