How to resolve Memory  Problems

Posted on 2004-08-16
Last Modified: 2008-02-01
I am developing an app with a huge form.  The form presents data based on a one to many realtionship between file 'tamain' and file 'detect'.  The layout of tamain is:

Public Type tamain
  ECode As String * 7
  ACode As String * 7
  txt00 As String * 240
  txt01 As String * 240
  txt02 As String * 240
  txt03 As String * 240
  txt04 As String * 240
  txt05 As String * 240
  txt06 As String * 240
  txt07 As String * 240
  txt08 As String * 240
  txt09 As String * 240
  txt10 As String * 240
  txt11 As String * 240
  Scenario As String * 240
  Target As String * 240
  ThreatAct As String * 240
  conID As String * 7
  ThreatLevel As String * 240
  adversary As String * 240
  AdvDed As String * 240
  AdvTact As String * 240
  AdvWeop As String * 240
  DefStrategy As String * 240
  BigDesc As String * 1000
  RTF As String * 5
  RTF01 As String * 5
  RTF02 As String * 5
End Type

The form has up to 15 tabs, each which hold one record from file 'detect'. The layout of detect is:

Public Type detect
  Eval_ID As String * 7
  DetOpID As String * 7
  DONumber As String * 2
  DOLevel As String * 2
  ShortDesc As String * 30
  LongDesc As String * 240
  TaskTime As String * 5
  DetText As String * 240
  DetRating As String * 10
  DetElement As String * 240
  AssessText As String * 240
  AssessRating As String * 10
  AssessElement As String * 240
  NeutText As String * 240
  NeutRating As String * 10
End Type

The amount of code written to support the editing and processing of the form is also massive. The .frm file for this form is 462kb.

There is not a lot of I/O happening.  Records are read in the beginning, massaged and written back out in the end.  The detect record are stroed in an array while being massaged.

The errors that I get are not consistent. Some times I get the 'VB is shutting down' message, sometimes it shuts down without any message, sometimes I get a 'out of string space message' and sometimes I get a 'shutting down because memory at location xxxxxx cannot be read.  I have tried it on another machine and get the same result.

I am hoping that there are some memory management techniques, functions, buffer settings or anything else that can help.  I realize that this is a large program and form but shouldn't the memory swap back and forth?  Any help would be greatly appreciated.  I have invested quite a bit of time into this for a client.  During development and unit testing I thought I was OK.  Now when the time has come to put it all together it's falling apart.

Question by:mlcktmguy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3

Expert Comment

ID: 11817568
What operating system are you running it on (primarily)? Windows 98-based operating systems will have trouble will excessively large forms because of the way they handle graphical resources, and unfortunately nothing can be done about this (grr), aside from using an NT-based operating system.

I believe Visual Basic itself also has some limits, especially on Strings, which is why you are getting the "out of string space" error. Again, I can't think of any way to "fix" this without reworking your code completely (or switching to a different language?).

I'm curious to see what other experts have to say about this too :-)


Accepted Solution

petoskey-001 earned 200 total points
ID: 11817627
I would recommend not using arrays to copy the whole database.  Databases are fast, there shouldn't be any problem reading or writing records as needed.  Assuming the database is local, the user wouldn't even notice the small amount of time it would take to read each record.  Using large arrays just opens you up to data integrity problems.  The user thinks they've changed something on screen, but it didn't get saved later because of an error a minute later.  Try to keep the data as fresh as possible.  The general rule I use is if it's not visible right now, you should think very hard about if you need it.

Usually I would keep only one record in memory, and a copy of that record in case I wanted to "undo" changes.

Having large (several hundred item) drop down lists just sitting hidden on a tab can cause resource problems too.

As stated Windows 98 has resource issues.  There is only so much ram in the whole system set aside for GUI controls.  I'm not sure how much, but I know that have an extra gig won't help because it just doesn't use it.  Also make sure youre up on the latest service packs (SP5?) because they do fix some memory holes that early VB6 had.

Author Comment

ID: 11817651
I am running Windows XP
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: 11817704
Well the out of string space is caused by running out of string space.  You declared your strings as String * 240, String * 10, etc.  

Dim str1 As String * 5

Then these could cause it too...

str1 = "Hello World"  
Text1.Text = "Hello World"
str1 = Text1.Text    

Check how big the DB or user control string is before you put it into your short string.  The other possibility is that your running out of memory.  See if you get the same reslts when you run your program without the IDE / SQL Server / Mozilla / whatever else you have running.  I know on my development machines I can chew threw a gig of ram in no time.

Expert Comment

ID: 11817711
Can't read memory at location X could be failure to allocate memory as well.  Run task manager (Ctrl+Alt+Delete) and watch the memory usage while your program runs.  You could have a memory leak.  Sometimes a timer function or recursive function that eats it, or API calls that keep allocating memory.

Author Comment

ID: 11825219
what is  SP5 a service pack for?  Do you have a link to it.

Expert Comment

ID: 11825941
The Visual Basic 6.0 SP5 Runtime only link is here...

The Visual Studio (VB6, VC6, etc) SP6 is here.  Note that this has more updates for Visual Basic, but has extra stuff too.

I can't seem to find the links that show all the bug fixes in each service pack, but it's possible one of those fixed bugs is causing your problem.

Expert Comment

ID: 11825944

Author Comment

ID: 11827161
I have run this on multiple machines and operating system (2000 Professionals) and still get the same errors.

More info: These are the 2 errors that I'm getting a message box:

The header bar says VB6.EXE - Application Error

The message text is:

"The instruction at "0x77fcc83d" referenced memory at "0x68676948" .  The memory could not be "written"

Click OK to terminate
Click on Cancel to debug the program

When I click OK I see another message box:

The header bar again says VB6.EXE - Application Error put it ipreceded by the 'name of the application"

The message text is:

The instruction at "0x77fcc8e1" referenced memory at "0x68676949".  The memory could not be written.


Expert Comment

ID: 11861896
Thanks for the points.  I thought I had posted this, but I dont see it here.

I looked up the errors you mentioned.  The only thing I could find suggested that the program was running out of memory, or possibly had a bad memory stick.  Since you used two machines, my guess is it was really running out of memory.  I didn't find anything about the specific memory locations or instructions.  Visual Basic doesn't really do well with debugging at the memory level, so I can't suggest what to do about that.  

BTW, what was your final solution?

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 121
Adding to a VBA? 6 85
Visual Studio search word table and return Cell index 8 77
checkbox to hide entire section 10 62
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 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