1

I'm using dotSpatials Map object to do some operations on a shape file. My program eats up memory when I'm using the code below to add a layer (MapLineLayer) and when I'm done with the layer I want my memory back. I can't manage to dispose of my Map object and it's layers.

        Map map = new Map {Projection = ProjectionInfo.FromEpsgCode(epsgCode)};
        try
        {
            map.AddLayer(filePath);
        }

How can I properly dispose dotSpatials Map?

CharithJ
  • 46,289
  • 20
  • 116
  • 131
haber
  • 13
  • 3

1 Answers1

0

Try ClearLayers(). If Map object is not disable and still causes memory leaks it may be a bug... Having said that, keep in mind that garbage collector will not release you memory immediately the Map control goes out of scope.

If you want you can execute GC.Collect immediately after you finish with the Map control (for testing purposes) but it is not necessary to put this code in your application as the Garbage Collector manages it properly.

GC.Collect();
GC.WaitForPendingFinalizers();
CharithJ
  • 46,289
  • 20
  • 116
  • 131
  • I've tried your suggestion and, unfortunately, it doesn't work. – haber Jul 16 '15 at 06:20
  • @haber: What did you do? How did you measure memory? Did you execute your code few times and invoke GC as I've indicated? – CharithJ Jul 16 '15 at 06:23
  • I didn't use GC.WaitForPendingFinalizers(); before. Adding it made the memory free. – haber Jul 16 '15 at 14:23
  • @haber: Great. So, there is no memory leak. No need to keep GC invoke methods in your code. GC will release memory appropriately when it is required. – CharithJ Jul 16 '15 at 20:15