Solved

Memory Errors in Large Application

Posted on 1999-01-27
6
215 Views
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?
0
Comment
Question by:cdickerson
6 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1470886
Cut your application in several little application.

It seems that this is not a good written application
0
 
LVL 4

Expert Comment

by:anzen
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

0
 
LVL 2

Accepted Solution

by:
dm_14 earned 100 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

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Expert Comment

by:Billaban
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.

HTH
0
 
LVL 18

Expert Comment

by:mdougan
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.

MD

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?
0
 

Author Comment

by:cdickerson
ID: 1470891
Thanks!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Public Sub, Empty Cell 7 57
to transfer string from C lanaguage to VBA 4 44
Adding to a VBA? 6 48
How does CurrentUser work? 10 25
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now