Release Memeory Issue after disposing Object of Mapbox

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Mar 23, 2015 at 8:32 AM
Hi Team,
Please suggest me to get Memory Released from mapbox control after disposing object of it.
as I use mapbox.dispose();.
any other idea to get things achieved.

Regards,
Sgoyal.
Coordinator
Mar 23, 2015 at 12:31 PM
Make sure you have mapbox.Map.DisposeLayersOnClose = true;
If you have set it this way, and you still have issues with memory not being released, open an issue describing you problem along with layers/providers that make up your map.
Mar 23, 2015 at 2:17 PM
Hi , I didn't find mapbox.Map.DisposeLayersOnClose = true; instead of this i found mapBox1.Map.DisposeLayersOnDispose = true; but didnt achieve the desired outcome. As i uses Sharpmap dll Version 1.1 .
I am using DataTablePoint Provider for creating SharpmapLayer.

My Code to Add SharpMapLayer on Map
mapBox1.Map.DisposeLayersOnDispose = true; 
                DT = getDataTable(@"$PathTOCSV\test.csv", ",", 1);
                DataTablePoint fd = new DataTablePoint(DT, "ID", "Longitude", "Latitude");
                SharpMap.Layers.VectorLayer VectorLayer = new SharpMap.Layers.VectorLayer("Test");
                VectorLayer.DataSource = fd;
                VectorLayer = VectorLayerCordinateTransform(VectorLayer);
               VectorLayer.SRID = 3857;
                VectorLayer.Enabled = true;
                mapBox1.Map.Layers.Add(VectorLayer);
                mapBox1.Map.ZoomToBox(VectorLayer.Envelope);
                mapBox1.Refresh();
My Button Close Event:-
private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                mapBox1.Map.Layers.RemoveAt(0);
                mapBox1.Refresh();
                DT.Dispose();
                mapBox1.Map.Dispose();
                mapBox1.Dispose();
                MessageBox.Show(mapBox1.IsDisposed.ToString());
                mapBox1 = null;
                this.Controls.Remove(mapBox1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Regards,
Sgoyal.
Coordinator
Mar 23, 2015 at 4:52 PM
Edited Mar 23, 2015 at 4:53 PM
Should have been DisposeLayersOnDispose.

I don't see that you dispose the DataTable that you use as source for your DataTablePoint provider.
The DataTablePoint provider doesn't do that.
Mar 24, 2015 at 7:09 AM
We already dispose the object of DataTable DT using Line of code:-
DT.Dispose();
As I Attached the Sample Code Please download from Sample App
Please Check..

Regards,
Sgoyal
Coordinator
Mar 24, 2015 at 10:04 AM
The problem is not within SharpMap. You need to call DT.Clear() before disposing the data table:
mapZoomToolStrip1.Dispose();
mapBox1.Dispose();
//MessageBox.Show(mapBox1.IsDisposed.ToString());

this.Controls.Remove(mapZoomToolStrip1);
this.Controls.Remove(mapBox1);

mapZoomToolStrip1 = null;
mapBox1 = null;

if (DT != null)
{
    DT.Clear();
    DT.Dispose();
}
GC.Collect();