EasyGIS.NET icon indicating copy to clipboard operation
EasyGIS.NET copied to clipboard

Memory Overflow Scenario

Open dusko23 opened this issue 2 years ago • 2 comments

Using the SFmap object on the OpenStreetMap shape file data raised some interesting points. The main goal is to produce acceptable raster maps from OSM data using fine-tuned RendederSettings. GetBitmap enables it.

My laptop has 8GB of ram.

Scenario A. When I was working with SFmap object sized to 5000 x 5000 pixels everything was working fine.

Scenario B. But when I switched to SFmap object size 5300 x 7200 pixels Memory Overflow starts appearing. All of the Memory Overflows were exposed by SFmap.Refresh(True)

To make the long story short here are my findings: Scenario A happily survived with the following image But Scenario B did not.

So I changed the code to: image and the success rate was much higher. However, Memory Overflow was still happening from time to time. I checked my bit several times and I can confirm that my part of the code has no memory leaks. So the only option was that SFmap might have the problems where Memory Overflow is the final result. Therefore I took the final "cure" from my end and after each GetBitamp Cycle I called Garbage Collector to do its job (I never use this at my end but in this scenario, it was the only option I was left with). image The result was spot-on, nearly.

There were two cases (out of 3,300 bitmaps) where SFmap.Refresh(True) still produces Memory Overflow. I checked the requested size of SFmap object and it was 7000 x 7000 pixels.

So I had to change my logic and use two smaller SFmap sizes. Like 3500 x 7000.

Conclusion.

  1. I think that there might be some issues in GetBitmap related to releasing resources after bitmap is delivered.
  2. I don't see any reason why SFmap object sized to 7000 x 7000 pixels would fail.

On my computer (8 gb ram) I am manipulating bitmaps in .NET environment (like 20,000 x 8,000 pixels) without a problem.

  • I hope that the scenarios described might help to find where the memory leaks are happening.
  • Adding an option to create larger SFmap object in the first place would also be great.

dusko23 avatar Aug 03 '22 20:08 dusko23

Are you disposing the returned Bitmap when you have finished using it?

    /// <summary>
    /// Utility method that creates and returns a new Bitmap Image of the current map displayed in the SFMap Control
    /// </summary>
    /// <remarks>
    /// The returned image should be disposed when you have finshed using the Bitmap
    /// </remarks>
    /// <returns></returns>
    public Bitmap GetBitmap()

wfletcher avatar Aug 03 '22 21:08 wfletcher

Yes, I do. image

dusko23 avatar Aug 03 '22 21:08 dusko23