Hi

How can I minimize the Memory use by a process created with Vb6

Thanks

Re: Question by Ralph

Ralph
Fri Jan 07 10:11:06 CST 2005


"Hermione" <Hermione@discussions.microsoft.com> wrote in message
news:470C187A-F6A0-4B4B-BE12-1655F857F666@microsoft.com...
> Hi
>
> How can I minimize the Memory use by a process created with Vb6
>
> Thanks

By using less memory.

An application uses the amount of memory it needs to do whatever it has been
requested to do. Therefore you have only two basic choices - request it to
do less over-all, or spread your requests over time so it does less at any
one moment.

For example, only load forms and resources when you need them and dump them
when you don't. Don't load 90,000 records if you are only planning on
chewing on 2 or 3 of them. Don't create a dialog box with animated icons,
floating banners, and marching ants - if you only need to ask for a file
extension. If you use some particular piece of data from a resource, don't
keep the whole resource around - load it once, capture the data, and unload
it. &etc.

Usually this question comes about because a programmer 'feels' his
application is using too much memory. Because of the way the VM works -
often your application isn't really using as much as you think or as much as
common tools show. How are you measuring it? What is 'too' much?

I have often seen cases where memory was blamed for sluggish behavior, when
in fact the app was just damn slow.

-ralph



Re: Question by MikeD

MikeD
Fri Jan 07 18:07:36 CST 2005


"Hermione" <Hermione@discussions.microsoft.com> wrote in message
news:470C187A-F6A0-4B4B-BE12-1655F857F666@microsoft.com...
> Hi
>
> How can I minimize the Memory use by a process created with Vb6


There are LOTs of ways. However, your program is going to use whatever
memory it requires. It primarily comes down to optimizing your code and
your use of controls. Here are a few things to keep in mind:

1. Don't keep variables "alive" longer than necessary. This means using the
proper scope for your variables. If the data is only required for a single
procedure, then use a procedural-level variable.

2. Declare your variables for the proper data type. Don't use a Double (or
worse, a Variant) when a Long (or even Integer, although Longs are
marginally more efficient) is really all you need.

3. Use controls that require fewer resources and less memory. For example,
use Frames as containers instead of PictureBoxes and use Image controls
instead of PictureBoxes to display graphics. Of course, functionality comes
into play here. If the Frame or Image control doesn't provide the
functionality you need that the PictureBox does, then naturally you need to
use the PictureBox. Along with this, use Label controls for static data
(data the user doesn't need to edit) instead of TextBoxes.

4. Use arrays efficiently. By this, I mainly mean that you might dimension
an array much larger than is ultimately necessary for performance reasons
(to keep from having to rediminsion it over and over, which is
time-consuming), but after the array is filled, reduce its size accordingly.

5. Release objects once they are no longer needed. This kind of goes along
with #1.

These are all just general guidelines (and only a few of many at that). If
you want specific recommendations on what you could do, then you'd need to
provide specifics about your program, your code, what
objects/controls/libraries you're using, etc.

Lastly, you might want to take a look at the following:

How to Optimize Memory Management in VB 3.0 for Windows
http://support.microsoft.com/default.aspx?scid=kb;en-us;112860

Now while this article is targeted for VB3, many of its recommendations and
suggestions apply to all versions of VB (well, maybe not VB.NET). If you
haven't checked it already, MSDN Library (VB6's Help) has topics regarding
memory management and optimization as well. Here's the URL for it online
(or see the same topic in an installed copy of MSDN Library):

http://msdn.microsoft.com/library/en-us/vbcon98/html/vbcondesigningforperformancecompatibility.asp

Mike