> -----Original Message-----
> From: franklin gray [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 05, 2002 12:14 PM


> I have a recursive function that calls itself many times.  If
> an error occurs, I notice that the call stack is very large.
>
> Two questions:
>
> 1) Will this stack overflow?

Yes but the recursive function has to be called many many times - like an
infinite loop kind of many.  I don't have any feel for the actual number of
calls this would take since it depends on the method you are calling and the
amount of stack space it requires.  If you get close to this limit its most
likely a bug.


> 2) Is there a way to clear the stack after each call?

I doubt you wan to do that!  The stack info contains the critical data
required to unwind the stack after recursion stops.

Instead of using recursion you can do the same thing with a loop and a stack
data structure.  At each iteration instead of recursing push the iteration
data onto a the top of a stack data structure (or the end of an ArrayList
lets say).


Jim Murphy
http://www.ironringsoftware.com

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to