System.Drawing out of Memory Error

Apr 18, 2011 at 11:45 PM

I am hoping that someone can help me with an issue I am having with the shape file labeler and an out of memory error I continually get. I am using labels to display GPS information for multiple units on a map. In order to display current information for the units I gather GPS data, clear existing labels and add new labels to the map with the current position. I am using the Mapwingis.labels.addlabel method to add the labels and the Mapwingis.labels.ClearAllLabels method to clear the labels. The program works as it should until I get a system exception. The exception states that a System.OutOfMemoryException was unhandled. Additionally the error report states that system.drawing was responsible for this error. It would seem as though there is a memory leak in this method.  Has anyone run across this before?

Developer
Apr 19, 2011 at 2:52 AM

 

First, try to update your version of MapWinGIS. In the current version there is only Labels.Clear() method. 
See the most recent version at the downloads page. I believe some leak in Labels class was fixed recently. 
Try to find out whether the leaking is bound to the Labels class manipulations or to the map redraw. 
I've tried the following code and it's not leaking:
	private void button19_Click(object sender, EventArgs e)
        {
            MapWinGIS.Labels labels = new Labels();
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100000; j++)
                {
                    labels.AddLabel("text", 0.0, 0.0, 0.0, -1);
                }
                labels.Clear();
            }
        }

Hope it'll help,

Sergei

 

Apr 19, 2011 at 7:50 PM

That did the trick Sergei, thank you.

Apr 19, 2011 at 8:28 PM

I had to make some adjustment with the new AciveX. Everything is working well except I cannot seem to get the new custom markers to work. I have posted my code below for anyone who has a chance to look at. Just a note that the hydrants variable is a public variable defined within the class.

 Dim HydrantMarker As New MapWinGIS.Image
       

 HydrantMarker.Open("C:\mobilemapping\images\hydrant.png", MapWinGIS.ImageType.USE_FILE_EXTENSION, True, )
     

 hydrants.DefaultDrawingOptions.Picture = HydrantMarker
 hydrants.DefaultDrawingOptions.PointType = MapWinGIS.tkPointSymbolType.ptSymbolPicture
 hydrants.DefaultDrawingOptions.SetDefaultPointSymbol(MapWinGIS.tkPointSymbolType.ptSymbolPicture)

 

What I am trying to do is set the hydrant marker as the default image for the points on the hydrants layer. What I get is just a point with no theme at all.

Developer
Apr 20, 2011 at 1:40 AM

I suppose SetDefaultPointSymbol isn't necessary it's used for the standard point symbols only. I wonder how you compiled this, default symbols defined by this enumeration: MapWinGIS.tkDefaultPointSymbol, not MapWinGIS.tkPointSymbolType

See class scheme of the ShapeDrawingOptions class, it should clear out what properties are needed to get the result:

http://mapwingis.codeplex.com/wikipage?title=Class%20schemes