Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Likely cause of "Out of stack space" in VB6

Is the most likely cause of an Error 28 - "Out of stack space" error an infinite or very deep recursion that is using up too much stack memory?

What are the other likely causes?

like image 578
CJ7 Avatar asked Dec 28 '22 03:12

CJ7


1 Answers

Your error is described over here in MSDN.

Note: This MSDN article is related to Visual Studio 2005. But it's likely to say that the same limits are for VB6.

  • Check that procedures are not nested too deeply.
  • Make sure recursive procedures terminate properly.
  • If local variables require more local variable space than is available, try declaring some variables at the module level. You can also declare all variables in the procedure static by preceding the Property, Sub, or Function keyword with Static. Or you can use the Static statement to declare individual static variables within procedures.
  • Redefine some of your fixed-length strings as variable-length strings, as fixed-length strings use more stack space than variable-length strings. You can also define the string at module level where it requires no stack space.
  • Check the number of nested DoEvents function calls, by using the Calls dialog box to view which procedures are active on the stack.
  • Make sure you did not cause an "event cascade" by triggering an event that calls an event procedure already on the stack. An event cascade is similar to an unterminated recursive procedure call, but it is less obvious, since the call is made by Visual Basic rather than an explicit call in the code. Use the Calls dialog box to view which procedures are active on the stack.

[update]

You can find the Visual Studio 6 (VB6) article over here.

  • You have too many active Function, Sub, or Property procedure calls. Check that procedures aren't nested too deeply. This is especially true with recursive procedures, that is, procedures that call themselves. Make sure recursive procedures terminate properly. Use the Calls dialog box to view which procedures are active (on the stack).
  • Your local variables require more local variable space than is available. Try declaring some variables at the module level instead. You can also declare all variables in the procedure static by preceding the Property, Sub, or Function keyword with Static. Or you can use the Static statement to declare individual Static variables within procedures.
  • You have too many fixed-length strings. Fixed-length strings in a procedure are more quickly accessed, but use more stack space than variable-length strings, because the string data itself is placed on the stack. Try redefining some of your fixed-length strings as variable-length strings. When you declare variable-length strings in a procedure, only the string descriptor (not the data itself) is placed on the stack. You can also define the string at module level where it requires no stack space. Variables declared at module level are Public by default, so the string is visible to all procedures in the module.
  • You have too many nested DoEvents function calls. Use the Calls dialog box to view which procedures are active on the stack.
  • Your code triggered an event cascade. An event cascade is caused by triggering an event that calls an event procedure that's already on the stack. An event cascade is similar to an unterminated recursive procedure call, but it's less obvious, since the call is made by Visual Basic rather than by an explicit call in your code. Use the Calls dialog box to view which procedures are active (on the stack).
like image 139
Martin Avatar answered Jan 11 '23 16:01

Martin