Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Out of stack space error with VB program

Status
Not open for further replies.

jax2

Programmer
Mar 27, 2001
18
0
0
US
Help.
I have a VB6 executable that I run on two machines simultaneously. It runs without error on machine #2, but will only run for roughly 30 seconds on machine #1 before exiting either with no warning/error or the "Out of stack space" error. I've watch the memory usage of the same app. on machine #2, and it fluctuates, but never continually increases. Same version of the program. The only difference I can tell between machines #1 and #2 is that machine #1 WAS running NT4 SP5, and I updated it to SP 6a, while machine #2 has been running SP 6a for sometime now. I've checked through all the code, and cannot find any variables which are created which are not deleted.... any ideas about debugging this problem would be _greatly_ appreciated. Thanks....
 
The "out of stack space" error has nothing to do with the amount of memory used on the machine.

The stack is a reserved area of memory of fixed size, and I know of no way to increase the stack size for Windows/VB. However, it's usually plenty large.

The stack is where most of your local variables are stored - variables declared within a function or subroutine. Stack overflows are usually caused by uncontrolled recursion. In other words, a subroutine calls itself over and over. It's easy enough to do in an event-driven environment.

Here's an example. Say you want to synchronize two listboxes so that when an item is clicked in one listbox the corresponding item is automatically clicked in the mirrored listbox:

Private Sub List1_Click()
List2.ListIndex = List1.ListIndex
End Sub

Private Sub List2_Click()
List1.ListIndex = List2.ListIndex
End Sub

This will result in a stack overflow when the first routine triggers the second, which triggers the first, which triggers the second again.
 
You should look for the following:

1. API calls - are different from an NT based platform. There are API calls that need some specual treatment in order to work in NT. (I have had this problem with ReadFile)

2. Loops like while-wend that do not finish(sometimes evenbecause of bad call API result).

Also you should:
1. strengthen the way you treat errors in the procedures you suspect to be the cause. (to find out the cause - add 'on error' code, eliminate the resume next)

2. get the result of every API call and put some MsgBox when it is bad to see which one does not work

Hope this helps, s-)


Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
I've run out of stack space when I had uncontrolled recursion. Look for events that call other events in an effort to reuse code.

I've had problems with this, and I found the best way to reuse code from event handlers is to put the shared code in a private sub or function and call it from the event routines that need it.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top