EasyGIS.NET
EasyGIS.NET copied to clipboard
Memory Overflow Scenario
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
But Scenario B did not.
So I changed the code to:
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).
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.
- I think that there might be some issues in GetBitmap related to releasing resources after bitmap is delivered.
- 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.
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()
Yes, I do.