• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

How to resolve Memory Problems

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.

  • 6
  • 3
1 Solution
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 :-)

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.
mlcktmguyAuthor Commented:
I am running Windows XP
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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.
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.
mlcktmguyAuthor Commented:
what is  SP5 a service pack for?  Do you have a link to it.
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.
mlcktmguyAuthor Commented:
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.

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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now