Monchopper
Posts: 14
Joined: Fri Aug 13, 2004 2:02 pm
Location: United Kingdom

Steady Decline in free memory? eVB

Fri Feb 18, 2005 12:07 am

When my app hits the code in sub objParser_OnGpsFix. The amount of free memory (settings > Memory) decreases steadily until it hangs the device Pocket PC2002.
Below is my code any help would be appreciated.
I've adapted code from the examples in the GPStools toolkit.

Private Sub objParser_OnGpsFix(objFix As GpsFix)
On Error Resume Next

Dim dblDistance, dblEasting, dblNorthing, dblAltitudeDiff

Dim objUTM As Position
Set objUTM = objFix.Position

objUTM.Grid = 1


Dim objElpse As GpsViewCECtl.Ellipse

Set objElpse = frmDetails_1.map1.GetByID(1)

If objElpse Is Nothing Then

Set objElpse = frmDetails_1.map1.NewEllipse()


objElpse.Width = 10
objElpse.Height = 10


Set objPen = Factory.CreateObject("GpsViewCE.Pen")
objPen.Width = 7
objPen.Red = 255
objPen.Green = 0
objPen.Blue = 0
Set objElpse.Pen = objPen

objElpse.ID = 1 ' Set to known ID, so we can find it with GetByID
End If

'Set objRect.Position = objPos
Set objElpse.Position = objUTM



frmDetails_1.map1.Update

'Pick up Markers co-ordinates
dblEasting = frmHoleDetails_1.Controls("lblEasting").Caption
dblNorthing = frmHoleDetails_1.Controls("lblNorthing").Caption

dblNPos = objUTM.Longitude
dblEPos = objUTM.Latitude

'Convert M to feet
dblDistance = DistanceCalc(dblNorthing, objUTM.Longitude, dblEasting, objUTM.Latitude) * 1.0936133

User avatar
johan
GpsGate
Posts: 15429
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: Steady Decline in free memory? eVB

Fri Feb 18, 2005 9:53 am

There is a memory leak in eVB itself each time an event handler is called. This might be it.

Try this:
Private Sub objParser_OnGpsFix(objFix As GpsFix)
Exit Sub

' ....
End Sub

That is, do not execute any code in the event handler and see if the memory leak stays the same. If it does it is the Microsoft eVB memory leak. If not it is a GpsTools memory leak.

If GpsTools is to blame, upgrade to GpsTools 2.20 and see if the problems continues, if it does make a new posting here and I will work this out.

Regards,
Johan

Franson Support

pamacs
Posts: 2
Joined: Fri Feb 04, 2005 1:29 am

RE: Steady Decline in free memory? eVB

Mon Feb 21, 2005 3:11 am

I have just the same problem - not eVB and PPC2002, but dotNETcf C# and WM2003. First I thought the memory leak could be in my program, based on the SerialPort sample in the SDK. After 2 days of searching for errors and finding nothing - I have just compiled and run the original sample application. If you start it on PPC, the system's free program memory begins to decrease. It is about 2 MB/hour on my system. I'm using the lates beta of GpsTools SDK.

Best Regards
Kaba

User avatar
johan
GpsGate
Posts: 15429
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: Steady Decline in free memory? eVB

Mon Feb 21, 2005 9:40 am

If you force the garbage collector to start, doesn't that clean up memory? Memory isn't freed up by .NET until needed by other applications, or until the application forces the garbage collector to run.

Regards,
Johan

Franson Support

pamacs
Posts: 2
Joined: Fri Feb 04, 2005 1:29 am

RE: Steady Decline in free memory? eVB

Mon Feb 21, 2005 5:01 pm

Sorry, I wasn't aware of this. Now when I force GC, the memory is cleaned up.
Thank you...

Monchopper
Posts: 14
Joined: Fri Aug 13, 2004 2:02 pm
Location: United Kingdom

RE: Steady Decline in free memory? eVB

Tue Mar 01, 2005 3:55 pm

After further investigation. It's not OnGpsFix where the leak occurs, it when I create the object. If I create it with events the memory steadily leaks, regardless whether there is a fix or not.

If I create without events then I don't have the memory leak.

I've got no idea if this is a eVB thing or a GPStools thing. I tried experimenting with the Odyessy "OSIUTIL.Win32" but it didn't make any difference.

The solution for me was.

Create objParser without events then use a timer on the form where the map is. The timer fires every 2 seconds to obtain fix and show position etc.

jhettena
Posts: 102
Joined: Wed Dec 15, 2004 6:21 am
Location: USA
Contact: Website

RE: Steady Decline in free memory? eVB

Tue Apr 19, 2005 9:45 pm

According to Microsoft, the real problem is not related to events, but the CreateObject() function. In fact, they suggest that any objects created with the CreateObject() function should be
made public to the application and only created once.

Thoughts?

robbiex
Posts: 38
Joined: Sat Apr 09, 2005 11:14 pm

RE: Steady Decline in free memory? eVB

Wed Apr 20, 2005 7:12 am

I am also finding a serious memory leak with either VisualBasic components or GPSTools. Memory usage increases by about 10KB per 2 seconds. All objects are disposed of on exiting from the event subprograms except for objParser which is public to the application. It will be interesting to see if making all objects public and only creating them once makes any difference. Also, we do have VS 2005 and it is possible that some VS 2003 problems have been corrected in the new VB.( VS 2005 has not been tried as yet and may not be compatible with GPStools.)

User avatar
johan
GpsGate
Posts: 15429
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: Steady Decline in free memory? eVB

Wed Apr 20, 2005 10:51 am

robbiex is talking about .NET CF, and the rest about eVB.

For .NET CF there is no need to dispose the objects, even though you can. NmeaParser is the only object that must be dispose after usage.

One reason you see a "leak" in .NET CF can be that .NET does not free memory right away. The garbage collector only runs when the system finds it necessary. This means you will see memory be eaten up in small chunks, and then freed up in large chunks. You can force the garbage collector to run (free up memory) by calling its methods (Take a look in the .NET docs).

If it indeed turns out that there is a leak in GpsTools, we will fix it right away.

Regards,
Johan

Franson Support

robbiex
Posts: 38
Joined: Sat Apr 09, 2005 11:14 pm

RE: Steady Decline in free memory? eVB

Wed Apr 20, 2005 3:51 pm

Hi Johan,

It is my understanding that the freeing of memory is better handled in VB NET, but it has been my experience that Windows Mobile 2003 SE is a pretty shaky OS and there can be strange behavior related to it and possibly to the compiler. A problem I haven't mentioned previously because I am still trying to track it down is that my program has unexpected "hangs" that require a kill to clear. The hangs happen spontaneously after the program has been running for a variable number of minutes and even with touching the touch sensitive screen.

jhettena
Posts: 102
Joined: Wed Dec 15, 2004 6:21 am
Location: USA
Contact: Website

RE: Steady Decline in free memory? eVB

Wed Apr 20, 2005 4:55 pm

eVB Specific:

Johan's many posts are extremely educational and apprecited. All of the external research I have done, however, indicates that the memory leaks related to the creation and destruction of objects from COM libraries that include enumerated types. This leads me to believe that, for the sake of mentioning it, programming with events versus non-events (and using a timer instead), may not necessarily be relevant.

I just thought this would be an interesting post.

Regards,

jh

User avatar
johan
GpsGate
Posts: 15429
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: Steady Decline in free memory? eVB

Wed Apr 20, 2005 5:03 pm


robbiex
Posts: 38
Joined: Sat Apr 09, 2005 11:14 pm

RE: Steady Decline in free memory? eVB

Wed Apr 20, 2005 5:18 pm

Hi Johan,

I let the program run for a long time. Total memory usage increased by about 1 MB and then there was no further increase. The value didn't reset to its initial reading, but it stayed stable. The program didn't hang although recurrent "program not responding" conduitions are still a problem.
Robbie

robbiex
Posts: 38
Joined: Sat Apr 09, 2005 11:14 pm

RE: Steady Decline in free memory? eVB

Wed Apr 20, 2005 5:22 pm

I stand corrected. After a 10 minute period of no increases, memory usage is again incrementing upward. The behavior is certainly erratic.
Robbie

robbiex
Posts: 38
Joined: Sat Apr 09, 2005 11:14 pm

RE: Steady Decline in free memory? eVB

Wed Apr 20, 2005 5:27 pm

My apologies for so many messages. This time the program hung after a second series of memory increments.
Robbie

Return to “GpsTools”