PDA

View Full Version : Mappoint 2006 memory Leak?



EvetsMostel
11-06-2006, 09:25 AM
I am using mappoint as an embedded part of my app. I'm currently doing a lot of FindNearby and FindPlaces calls. Over a course of several hours, mappoint goes from have 10MB of memory to over 400MB. Is there a way to release these "find" results? It's really the only thing I'm doing other than GoTo location calls.

Steve

Mattys Consulting
11-06-2006, 09:55 PM
Steve,

Post your code, it's might be in there somewhere ...

Winwaed
11-07-2006, 08:22 AM
Yes, you need to clear/reference references to all MapPoint objects when you've finished with them.

After saying that, MapPoint does tend to grow over time when you're doing batch work (eg. lots of route finding). For "application" MapPoint, there's a minimise/maximise trick which forces the garbage collector to run.
An alternative is to stop it and restart it - this should also work for the control.


Richard

Eric Frost
11-07-2006, 09:33 AM
For "application" MapPoint, there's a minimise/maximise trick which forces the garbage collector to run.

That is a nice trick, I will have to try it. I have always been closing and reopening it when I run into the problem of the MapPoint app growing into hundreds of MB and it slows down.

Eric

Wilfried
11-07-2006, 03:32 PM
Hi Steve,


10MB of memory to over 400MB. Is there a way to release these "find" results

do them in a separate object that you dispose once a while.

EvetsMostel
11-08-2006, 09:25 AM
Yes, you need to clear/reference references to all MapPoint objects when you've finished with them.

After saying that, MapPoint does tend to grow over time when you're doing batch work (eg. lots of route finding). For "application" MapPoint, there's a minimise/maximise trick which forces the garbage collector to run.
An alternative is to stop it and restart it - this should also work for the control.


Richard

Not sure how to "Clear/reference"... Any objects I create including "FindResults" are just declared on the stack during a member function, and thus are deleted when the function is complete. What exactly is the "minimise/maximise" trick? Are you saying that you show or hide the window? or are you maximizing the window? Wouldn't that be pretty ugly to the user?

Steve

Winwaed
11-09-2006, 07:42 AM
Minimize/Maximize: Possibly, it depends on your application. Wilfried discovered it, so if you search the forums you'll find his solution. You have to send messages to MapPoint's window - the hide/show property isn't enough.

Objects usually end up on the heap and not the stack - this is an important difference between objects and value types (like integer).
MapPoint objects actually COM references.
I'm not sure what language you're using, but in VB 6 you will need to set each object reference to nothing when you've finished with it, eg:

set myPin = myMap.AddPushpin(....)
' (Do something interesting with myPin)
set myPin = Nothing


VB6 is then clever enough to delete the object when all references are removed.
In C++, you would use "Release()" on the object reference - and you have to be a little bit more careful with other references.


Richard

EvetsMostel
11-10-2006, 10:11 AM
Well, I am using C++, but can't call Release() (at least on the FindResults object), as it isn't part of the Class. So, not sure what you're referring to.

Steve

Wilfried
11-10-2006, 02:10 PM
Hi,

This is a typical inter-application problem where no garbage collector can clean, unless it is in the object itself.

Consider this function:

FindResults results = map.ObjectsFromPoint(x, y);

It create a collection on the heap. When the function returns the address of the structure is in EAX register. the called application can and may not free this because the calling application need it.

So there is no method provided in the FindResults to free it (and I doupt if this is possilbe in COM factory) it will persist in memory forever until the server is destroyed.

So for 24/7 applications do these things in a separate object witch you once a while destroy.

EvetsMostel
12-21-2006, 01:26 PM
What other calls besides this one does this?
FindResults results = map.ObjectsFromPoint(x, y);

I use FindResults all over the place. Good C++ practice is that it detroys itself when deconstructed, unless it has a Release, function which it does not. Are you telling me that there is no way to clean this up?

VC_Man
12-22-2006, 02:13 AM
I don't have a lot of programming experience, but you could use new to reserve dynamicly memory for a Findresults object. You put your object in the allocated memory, after you've done it you can cal delete.

I don't know why you should use Release via COM.

Something like this:
CFindResults FindRslt = new CFindResult;
FindRslt = Map.GetObjectsFromPoint(x,y);

Than when you don't need it anymore, do:
delete FindRslt;

But doing:
CFindResults FindRslt = Map.GetObjectsFromPoint(x,y);
You can't use the delete key, so you should do this by Release(), but if that is not possible, than you've to solve the problem like our friend Wilfried said. The minimize/maximize thing. Maybe it's ugly to the users, but you could prompt message that mappoint is freeing memory and than will continue.

I hope I don't say stupid things, but that is what it came up in my mind. And I just try to help, like others help me ;)