ThinkGeo.com    |     Documentation    |     Premium Support

Removing all objects from a layer

My application involves a lot of dynamic objects on the map.



To achieve this I have a 5 second timer which will clear and redraw the items on these layers, either with different properties or locations.

The Issue I am experiencing is that the application’s memory is increasing  after each redraw.

This leads me to believe that some remnants of the  removed items are still held in memory or not being completely removed.



the cods I am using the clear the layer  is as follows.

        MyLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear()

        MyLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

        MyLayer.InternalFeatures.Clear()





Is this all I need to do.  or is there something else that is required to free up the memory.








Hi Steve, 
  
 I created a simple sample, but haven’t succeed reproduced that, please let me know where is the different between my sample and your project. 
  
  
 Collection<Feature> allFeatures;

        private void DisplayMap_Load(object sender, EventArgs e)
        {

            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

            ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer(@"…\SampleData\Data\USStates.shp");

            InMemoryFeatureLayer layer = new InMemoryFeatureLayer();
            layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green)));
            layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            statesLayer.Open();
            allFeatures = statesLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns);
            statesLayer.Close();

            foreach (var feature in allFeatures)
            {
                layer.InternalFeatures.Add(feature);
            }

            LayerOverlay overlay = new LayerOverlay();
            overlay.Layers.Add(layer);
            winformsMap1.Overlays.Add(overlay);

            winformsMap1.CurrentExtent = new RectangleShape(-123.41875, 41.96396484375, -107.158984375, 30.36240234375);
            winformsMap1.Refresh();


            Timer timer = new Timer();
            timer.Interval = 5000;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            InMemoryFeatureLayer MyLayer = (winformsMap1.Overlays[0] as LayerOverlay).Layers[0] as InMemoryFeatureLayer;

            MyLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();
            MyLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            MyLayer.InternalFeatures.Clear();


            MyLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green)));
            MyLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            foreach (var feature in allFeatures)
            {
                MyLayer.InternalFeatures.Add(feature);
            }
        }
 
  
 Regards, 
  
 Don

Thank Don.   It appears, I am clearing the items correctly. 


Hi Steve, 
  
 I am glad to hear you solved your problem. 
  
 Regards, 
  
 Don