Kaspersky Internet Security 7.0
Information Technology

Optimizing Visual Basic Projects for Memory


Visual basic is a programming language that undertakes, what is generally called a third generation event driven program. Microsoft came out with the VB development environment to help its programming model called COM.

In Visual Basic it’s of paramount importance that programmers optimize it with regards to memory if they want their project to be more effective in terms of application.

Rid yourself of dead codes

As can be imagined, a dead code is a code that is not operational and is quite unnecessary. This means that it can be removed.

In Visual Basic, like other programming languages, there are various uncalled sub-programs and functions, in a dead code. Moreover, such a code also has various unread and unwritten properties, as well as, various constants that are not referenced.

Removal of dead codes is necessary as, such codes only use up memory and lead to a slow speed of execution. If there are a large number of dead codes in your project then there is an increase in errors and therefore an increase in maintenance needs.

Use variable length strings

Variable length strings occupy a lesser amount of memory then fixed length strings. The problem worsens when not only do you use fixed length variables, but they also have a long string.

There is also another reason why fixed length variables must not be used. This is in the event of your migration towards the use of VB.NET. You will definitely get a better performance from the use of variable-length strings, as VB. NET is not a native supporter of fixed-length strings.

Use dynamic variables

Dynamic variables are those, which are only created at the time when one enters the procedure and are removed or destroyed, at the end of the procedure. This is the reason why they are also called procedure level variables.

Unlike the static variables, that are also a part of Visual Basic, these do not reside in the memory, throughout the execution time. Static variables need to be avoided because their memory consumption is much more than dynamic variables.

Memory reclamation

There are times when you use Visual Basic, when the necessity of using static variables will present itself. It is important to get rid of them after they have served their purpose. This is in order to reclaim all the memory space that they had been occupying.

As aforementioned, dynamic variables are destroyed, at the end of the procedure and hence memory reclamation is not a problem.

Memory reclamation from arrays

Arrays occupy a lot of memory. As in the case of variables, even here the static variety of arrays occupies more space as their size is fixed throughout the life of the program. Here, preferably, dynamic arrays must be used, if you want to optimize the memory.

This is because such dynamic arrays can be resized. However, there are various ways in which memory can be optimized for both the types of arrays.

Avoid variants

Variants are slow and consume a lot of memory. Try to use integers instead as they are much faster. In large projects the extensive use of integers is beneficial as the speed of execution is also increased.

Memory optimization for Visual Basic is a quick and easy process. Try incorporating it while you work with this programming language.

Copyright © 1996-2008 Genesi S.r.l. - E-mail info@genesi.it | VAT ID: IT01680570676