Memory leaking when placing pins

I have a SQLite database that has my label names and the lat & long, I am using a while db reader to get the name, lat and long from the database, with each iteration I am calling the method below to put the pins on the map.

I clear the layer and cycle through the 100+ records and rewrite the pins every 20 seconds, but I am bleeding memory with each cycle …maybe 250kb but it adds up over time…clearly I am not handling this correctly…

Any guidance would be appreciated.

    public void mapPins(string callLabel, double gridLat, double gridLong)
    { 
        var places = new[]

         {
            new { Lat = gridLat, Lng = gridLong, Name = callLabel },

        };
       
        //151N - 33.5

        // it's default setting but just in casevar gs = new GlobalSettings() {AllowLayersWithoutProjections = true};


        var sf = new Shapefile();

        // use empty string to create in-memory shapefile
        sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
        int fieldIndex = sf.EditAddField("Name", FieldType.STRING_FIELD, 0, 20);
        
        
         foreach (var place in places)
        {
            // convert our degrees to meters in map projection
            double projX = 0.0, projY = 0.0;
            axMap1.DegreesToProj(place.Lng, place.Lat, ref projX, ref projY);

            // create shapes for each location
            var shape = new Shape();
            shape.Create(ShpfileType.SHP_POINT);
            shape.AddPoint(projX, projY);

            // add it to shapefile along with name
            int shapeIndex = sf.EditAddShape(shape);
            sf.EditCellValue(fieldIndex, shapeIndex, place.Name);
        }
        sf.Labels.Generate("[Name]", tkLabelPositioning.lpCenter, true);
        sf.Labels.AvoidCollisions = false;
        sf.Labels.FontSize = 6;
        layerHandle = axMap1.AddLayer(sf, true);
    }

Sorry for not replying sooner.

Assuming you’re using a recent version of MapWinGIS, MapWinGIS v5.3 was just released.

I see you create a new shapefile every time you add a pin. I would suggest creating 1 shapefile, adding it as a layer and add each pin to this layer. You might want to look at Shapefile.EditUpdateShape() to override the previous pin. And just call AxMap.Redraw() to update the map with the updated pin.

You can also have a look at Drawing layers.