View Full Version : Need Help with memory managment.

11-28-2006, 11:17 AM
I have read as many posts here as possible regarding memory managment and now need help with priorities in keeping my application stable and running smoothly.

I have an MS Access 2000 application using the Mappoint OCX control. The application gets very slow after just a few minutes. I understand the the minimize/maximize window routine will not be of any benefit on my Access form.
I plan to release memory from objects whenever I can and probably schedule a map save/restore periodically to free up whatever else I can.

I assume the objects that need addressing are the map, locations, pushpins, and routes:
objmap, objloc, objpushpin, and objroute.

Here is how those variables are used:

My application will track about 10 vehicle and about 60 locations per vehicle. Because of weak GPS signals, many position reports falsely report 0 speed and 0 heading. I use a distance/time calulation to previous points to guess if the vehicle is moving or not.

Because of stopped vehicles, I have fewer pushpins than locations.

Routing is only used sporatically to show a path from the most recent location to a destination but it re-calculated every time the vehicle moves.

Can someone please first confirm that these simple steps (**) would be appropriate for memory management?

When (objroute.delete) then
(**) objroute = nothing ?
(**) objroute = objmap.route ?

When objmap.Datasets(1).delete
(**) I loop through and set all the pushpins to nothing ?
(Wilfried has kindly given me a loop to step through all my pushpins)

I use an array of locations objloc(1-60) every time I display a set of points. I use the same arrary over and over after clearing the dataset.

Do I need to;
(**) set each objloc to nothing before I re-use it?

Finally, I wll save the map to disk every 15 minutes or so and then reload it.
Do I need to set these before I re-load the map?
(**) objmap=nothing ?
(**) objmap =Mapcntrl.map ?
(**) objroute = nothing ?
(**) objroute = objmap.objroute ?

These techniques have been discussed here in various posts, but not all in relation to one programming tool or display environment.

Can anyone help in evaluating these techniques?

11-29-2006, 04:36 AM

Setting the object to nothing before assigning it again will not make any difference. What could make difference is setting it to Nothing the moment you dont need it anymore. This is not needed if the object is a pointer on the stack in a function, because as soon as the function return that part of the stack is not reacheable and objects should be freed.

11-29-2006, 11:47 AM
I am definitely doing something wrong, maybe using a dim statement inside or loop or something else that improperly uses resources. I am not a programmer by profession, and my inexperience is beginning to show now that I want to deploy the app that I spent the last couple of weeks working on.

Everyone in the office loves the app for about 15 minutes and then it becomes unusable.

11-29-2006, 01:53 PM

I know nothing of VB or VBA but trying :) You mention a Dim statement inside a loop. Whell as far as I can see in VB code the Dim does assign (or assign and create) the object in question (correct me if I'm wrong).

Now suppose you do this (dont matter the syntax I dont know):

while (someCondition) do
Dim Foo as integer;
// ...
This will not harm. the integer Foo is just placed on the stack. Nothing is allocated. But now this:

while (someCondition) do
Dim Foo as someObject;
// ...
While Foo is also just an integer (yeah in fact it is a pointer to the object) and just placed on the stack as in previous example, the object someObject is created here. In the next irretation of the loop, the object where Foo points to is destroyed and a new someObject will create. So here is a lot of memory allocation / deallocation. While is is consuming mutch time it will also fragment memory because the deallocation is not nececary immediatly.

Even in dotNet you can this way easy fragment memory even with the nice garbage collector :)

Hope this helps understeanding ? Hope my explanation make sence. English is not my native language.

11-29-2006, 02:55 PM

Thanks for the quick reply. Your comments probably stopped some unnecessary re-writes. I will now go through my code looking for objects that are dimmed within the loop. I think that I did most of the dim statements at the top and did the "set" within the loop.

Thanks once again.

11-30-2006, 12:43 AM
OK, I think I figured it out. Sort of a DUH! though.

I was using the same routine over and over to add my custom pushpin symbols and never reusing them. So I have thousand of pushpin symbols in the set.

I need to load about 75 images and then be able to refer to them by ID number. Can anyone think of a easy programatic way to add and then refer to the numbers. It would seem that I would need to get the number after they were added and then create an array or tabe with the ID number and the name of the image in each record. Then I would use a lookup query to get the image number and then refer to it.

Or something like that.

11-30-2006, 02:22 PM

Glad first problem is solved :)

Can you clarify the last question in more simple Englisch ? (English is not my native language).

12-01-2006, 10:58 AM
I resolved the problem in a similar post. At the time I knew that I had to import 75 custom pushpin symbols to illustrate my vehicle tracking program. When they are imported Mappoint assignes them a simbol.Id number beginning with 336. I could not figure out a way to refer to the proper symbol after they were imported without building a lookup table as I imported the symbols. Then I found out that I can call the symbols by name and that the symbol name is the same as theie dos file name. Here is the solution I posted in the other thread:


That one I got on my own after some tinkering around. I have loaded the 75 icons into a map through the Mappoint application using the icon loader suggested in another of my posts here.

I save the map, because the user added icons are saved in the map. That way I have an expanded library without having to load every time.

When running my Access application, I first load the map with the icons installed and then I call them by the file name they had when loaded.

I use:
objPushPin(xy).Symbol = objmap.Symbols.Item("Car.bmp")

It seems to work fine and the program is so far stable.

Thanks for all your help