Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Memory Errors in Large Application

Posted on 1999-01-27
Medium Priority
Last Modified: 2010-05-03
I'm working on a poorly-designed app with 97 forms, 38 bas modules, and 61 classes, all contained in one executable (over 7 megs). In addition, there are calls to 10 external dlls, including some Win APIs. The clients have 64 or 80 megs of memory, and plenty of available disk space.

The problem is that we're experiencing random, intermittent VB application errors - memory couldn't be written/read - that typically aren't reproduceable. 7 machines can be running the exact same source code, but don't experience the same problems at the same time.

Can anyone point out some areas that should be investigated as the source of these problems? Surely executable size is one of them. How large can VB reasonably handle one exe? What other culprits might be involved?
Question by:cdickerson
LVL 14

Expert Comment

ID: 1470886
Cut your application in several little application.

It seems that this is not a good written application

Expert Comment

ID: 1470887
I think You're running near the limit of objects VB can handle, that is, VB doesn't give You warnings whenever compiling the app but at run time it hits its limits and crashes miserably, I suggest You to take a look at VB documents about project limitations (objects, forms and so on) and to check out if it's the case, it the problem is this then You'll need to sit back and think about redesigning Your app splitting it in different pieces (EXEs) and linking them together by wrapping them inside some ActiveX "macro" classes


Accepted Solution

dm_14 earned 400 total points
ID: 1470888
I have had this problem with one of my projects in the past and the following has helped

(1) reduce the number of forms that are displayed simultaneously
(2) Clear all objects when a form is discarded
ie. Set ObjectVar = nothing, Set Form1 = nothing
(3) When loading a form check for available system resources and memory. If it gets low (set a limit, you need to investigate what is an acceptable level), display a message to the user to close some forms or other apps and stop loading.
(4) It may be the way you are using the API that can cause memory leaks in your program. The easiest way to determine this is to use a package such as BoundsChecker - which can be identify memory leaks and improper usage of APIs
(5) Remove unused code
(6) If some forms are similar in design and only have a few extra/less controls then create a generic form and add/remove controls via code
(7) If you use bitmaps in your forms then store them in a resource file instead and load them in your form at run time (ie. via code)
(8) Try creating OLE Servers (called ActiveX EXEs now) which contain the different functionality of your modules
eg, 1 form as an ActiveX EXE that you call from within your code, this way if an error occurs you can identify which form is causing the error

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 1470889
Does this code have any error handling?  Do you know exactly what is happening when the sporatic crashes occur?

FYI  NuMega makes a product called FailSafe (I have downloaded a trial version, but haven't had the time to unzip and play with) which presumably would aid in identifying the failure points, i.e., call stack, memory state, blah, blah .... However this wouldn't necessarily tell U squat about the root of the problem.  NuMega business is predominately (to my knowledge) debugging and they have branched into the VB.  They have other tools which are diagnostic in nature, but my experience with their C/C++ tools (possibly not relevant to the VB tools) is that the tools gag on large complex applications.  I suspect that the utility of these IDE add-ons is when it is used during development to avoid problems as the are developing, not just looking at the resultant beast and expecting a magic bullet, like fix this one memory leak and life will be good.

Ok, I'm off my soapbox.

BTW, I would be interested to here from anyone who is using the NuMega VB Suite and has comments.

LVL 18

Expert Comment

ID: 1470890
The most common memory related errors are caused by:

Running out of GDI resources because of having too many windows open - and/or hiding windows instead of unloading them.  Be sure that when the application closes a window it unloads it, then sets [form name] = nothing.

Too many controls on a form - usually not an intermittant problem - limit of 255 controls per form.

Dynamically allocating too much string space.  I think there is a 64K limit to the amount of space you can dynamically allocate (try redimming an array to hold 10,000 text lines and you'll probably hit this error). Be careful of recursive routines that declare a lot of local variables, as this will cause the same problems.

Coding forms or modules with more than 64K of code (codespace is limited to 64K per module)

You can also get the error you mentioned when calling external DLL functions if you are not careful about passing the parameters correctly.  Remember, VB passes everything by reference (by default) except Strings which it always passes by value - however when passing strings you should always explicity put the word ByValue in front of the string parm in the declare statement as this tells VB to append a null termination character to the string (which most C programs expect).

Also, be aware that some of the Declare statements in the WinAPI help file are incorrect, they might miss the ByValue in front of some strings, or they might declare something as Long (or whatever) when it might be an optional parameter and should be declared "as Any".

Very rarely, will you have problems with referencing deallocated variables, but if you are doing any multi-threading, this is a constant cause of this error.

Hope this gives you something to go on.


Looks like dm_14 and I were typing at the same time, sorry for the duplication.  Also, as for the size of the EXE.  Yes, it is excessive, but I have seen VB apps that size that were successful.  Windows swaps code in and out of memory if necessary, but with the amount your users have, it shouldn't be a problem (maybe it will be slower).  Perhaps, as someone suggested, you could split this out into two or three related applications?

Author Comment

ID: 1470891

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question