Click to See Complete Forum and Search --> : Out of Stack Space


VB Beginner
March 16th, 1999, 11:19 PM
What does this error message mean? And how can I get rid of it??

Chris Eastwood
March 17th, 1999, 04:39 AM
Hi


This error usually happens when a routine is called recursively (i.e. it calls itself - usually without you knowing).


For example, the _Paint event can be triggered to call itself, as can the _Resize event.


A simple way to stop this happening is to check within the procedure causing the error :


eg.


Private Sub Form_Resize() ' Or XXControl_Resize or XX_Paint or Whatever


Static bAlreadyInHere As Boolean ' Static variable to hold state



If bAlreadyInHere Then Exit Sub


bAlreadyInHere = True

'

' Do Stuff

'

bAlreadyInHere = False


End Sub


Regards


Chris Eastwood


CodeGuru - the website for developers

http://www.codeguru.com/vb

May 26th, 1999, 07:35 AM
Everytime a function (or sub) is called the compiler has to do some things.
First it needs to know, who called the function (that is the "Where do I have to jump, when this is all over?" - address).
Second it needs to keep the local variables somewhere. This is all done in the "Stack". When the function exits the stack is deleted.
When you call another function in this function the compiler (as above) remembers the returnadress, reserves space for local variables and so on.

Under Win32 (NT, 95/98) the stack space is huge (normally about 1Meg, but easily more) compared to 64K in good ol' 16 Bit times.
But even 1 meg is eventually full ...

Normally this shouldn't be a problem (remember : it worked with 64K ...), but when you carelessly use rekursive functions (and VB does
a lot of them (Events that fire themselfes...)) you wil go "Out of Stack Space" ...
So, if you use rekursive functions : keep the memory-footprint small (e.g. don't pass Strings ByVal,...) and always make sure the rekursion terminates ...