Memory usage increases without control

Dec 7, 2011 at 11:11 AM
Hi everybody,

I'm developing a airplane tracking software that shows the movement of targets on a vectorial map. It works quite good, without any exception/error.

Testing the program memory usage, I realize that it increases without limit. I have isolated the problem, I know that is related with the DrawPoint() method and the memory management of the drawing layers.

There is a variable that stores the location of the airplane, I'm simulating the movement of the objects by checking target position and drawing a point there every tick of a timer, cleaning old drawings previously in order to simulate the screen refreshment. It works fine, shows all that I want.
Here's a simplified example in C# based on my source code:


public partial class Visor : Form, MapWinGIS.ICallback, IDisposable
{

int tracking_screen; //Screen drawing layer handle
MapWinGis.Point plane; //Data Structure that stores the plane location

public Visor()
{
InitializeComponent();
}

private void Visor_Load(object sender, EventArgs e)
{
plane=new MapWinGis.Point();
tracking_screen=axMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);

}

...

private void timer1.tick()
{
axMap1.ClearDrawing(tracking_screen);
tracking_screen=axMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList); // <<---- May be the problem it´s here
axMap1.DrawPointEx(tracking_screen,plane.x,plane.y,8,(Convert.ToUInt32(ColorTranslator.ToOle(Color.Red))));

}

...
}


The memory increase only happens when the timer is enabled so I think is due to I use the new drawing assignment for the point (NewDrawing) every tick, may be it reserves memory in each call and the ClearDrawing method don't free the room used by the drawing layer.

You would think the problem can be solved by deleting the code line that contains the call to NewDrawing method, I have tried it but after Clearing Drawing it doesn't shows the new point drawn, you can't draw a point and show it on the screen without calling first the NewDrawing method.

What can I do? Am I doing something wrong?

Thanks in advance.

David.
Apr 25, 2012 at 8:15 AM

Hi David,

Have you got the solution for the above problem? If yes, could you just let me know the solution to it.

 

Thanks,

Viswanathan

Sep 1, 2014 at 4:30 PM
Edited Sep 1, 2014 at 4:31 PM
Hi,

I Don't know if anyone is still interested but doing rather the same code with 4.8.8, I found also that Cleardrawing disables future drawings to the same layer and that it's necessary to recall NewDrawing. With following lines, in a loop, I didn't notice memory increase and drawing handler keeps the same value
With WinMap1
.ClearDrawing(gpsLayer)
.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList)
.DrawPointEx(gpsLayer, gps.x, gps.y, 12, 255)
.Redraw()
end With
By the way, I noticed that it's necessary to set .DisableWaitCursor = True to avoid cursor update during .Redraw() but setting it to false and true again doesn't work, cursor keeps updating after "false"....


As a conclusion, it seems that ClearDrawing should be RemoveDrawingLayer and that there is no function EraseDrawing.

Olivier
Developer
Dec 2, 2014 at 3:12 PM
Checked this issue for pre-release version of v.4.9.3. Wasn't able to reproduce anything in both cases. a) ClearDrawing indeed works as RemoveDrawingLayer. It should be called for each NewDrawing call. Otherwise there will be a leak. And indeed there is no way to clear the drawing layer only to remove it, which is a pity, will add it to my TODO list. b) DisableWaitCursor after such "true -> false -> true" scenario hides cursor as it should.