Solved

How to resolve Memory  Problems

Posted on 2004-08-16
10
237 Views
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.

0
Comment
Question by:mlcktmguy
  • 6
  • 3
10 Comments
 
LVL 7

Expert Comment

by:Burbble
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 :-)

-Burbble
0
 
LVL 7

Accepted Solution

by:
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.
0
 
LVL 1

Author Comment

by:mlcktmguy
ID: 11817651
I am running Windows XP
0
 
LVL 7

Expert Comment

by:petoskey-001
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.
0
 
LVL 7

Expert Comment

by:petoskey-001
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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:mlcktmguy
ID: 11825219
what is  SP5 a service pack for?  Do you have a link to it.
0
 
LVL 7

Expert Comment

by:petoskey-001
ID: 11825941
The Visual Basic 6.0 SP5 Runtime only link is here...
http://www.microsoft.com/downloads/details.aspx?FamilyID=bf9a24f9-b5c5-48f4-8edd-cdf2d29a79d5&DisplayLang=en

The Visual Studio (VB6, VC6, etc) SP6 is here.  Note that this has more updates for Visual Basic, but has extra stuff too.
http://www.microsoft.com/downloads/details.aspx?FamilyID=a8494edb-2e89-4676-a16a-5c5477cb9713&DisplayLang=en

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.
0
 
LVL 7

Expert Comment

by:petoskey-001
ID: 11825944
0
 
LVL 1

Author Comment

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


0
 
LVL 7

Expert Comment

by:petoskey-001
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?
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…
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…

705 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

19 Experts available now in Live!

Get 1:1 Help Now