Out of memory on Image.Load

Hello,

We have tried to process the DWG at (many_hatches.zip) with the Aspose.Cad library version 25.9 and the following code:

var image = (CadImage)Image.Load(fileDownloadPath, new LoadOptions { CancellationToken = cancellationToken });

foreach (var layout in image.Layouts)
{
    var (width, height, _) = VisualisationGeneratorUtils.ComputeImageSize(layout, image.Bounds);

    var svgRasterizationOptions = new CadRasterizationOptions
    {
        PageWidth = width.Value,
        PageHeight = height.Value,
        BackgroundColor = Color.White,
        DrawType = CadDrawTypeMode.UseObjectColor,
        ExportAllLayoutContent = true,
        Layouts = [layout.LayoutName],
        Quality = new RasterizationQuality { Hatch = RasterizationQualityValue.Low }
    };

    var svgOptions = new SvgOptions
    {
        VectorRasterizationOptions = svgRasterizationOptions,
        TextAsShapes = false,
        Timeout = timeout,
        CancellationToken = cancellationToken
    };

    await image.SaveAsync(fileToUploadPath, svgOptions);
}

The Image.Load instruction is loading more than 4GB of memory and it crashes our processing machines with an out of memory exception.

This DWG has a ridiculous amount of hatches which is almost surely the issue and we would be more than happy to drop the hatches. We have used the Quality property in CadRasterizationOptions but we could not find any such option at load time.

Is there any way to reduce the memory consumption of a loaded DWG or any other suggestion on how to achieve this use case? Given the fact these DWGs are not common we would not want to increase the memory just for these edge cases as it is already enough for normal usage.

Thank you in advance for the help!

@ninovismo,
Hello,
thank you for all details, we created CADNET-10256 to investigate possible solution.

1 Like