Thursday, January 19, 2017

#1 2005-10-13 02:42:23 pm

From: MalasaƱa, Madrid
Registered: 2002-11-20
Posts: 2014

What is "Stack overflow"?

This is a very bad thing you must avoid. Some times an executing code can overflow the heap-memory of the application, causing memory leaks and crashes.

It's the same as if you attempt to eat an elephant in a single try, allocate a square, or a juggler playing with two hundreds of marbles.

Here is a tricky sample of stack overflow:


set x to {alias "path:to:some file.dlg"}
set end of x to x

tell application "Finder" to duplicate x

We created a recursive list containing itself, and passed such list to the Finder, which is primarilly absurd, a cool cultivation for a stack overflow.

The most common sample of stack overflow is when you attempt to create a list of (eg) 10.000 items involving AppleScript's text item delimiters. Classical example:


set x to (read alias "path:to:some file.txt")

set AppleScript's text item delimiters to space
set x to x's text items
set AppleScript's text item delimiters to {""}

If the related file contains 10.000 spaces, this code will throw a stack overflow error, since the approximate limit is 4.060 items. However, Apple points that this error is not present for Unicode text, and promised trashing out this error for next AppleScript releases (OS 10.3, the Panther, and further).

You can find some more examples of stack overflow errors with recursion here.

Filed under: Finder



Board footer

Powered by FluxBB

[ Generated in 0.042 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)