teotigraphix.blog.show()

Flex2 :: StackOverflow #1023

Hello,

I thought I would share a little info and troubles I just had. When creating the documenter, I am now testing it on Adobe's 550 some files along with my 70 files in my framework. So those two added together was just over 600 files.

The application was trudging along perfectly untill last night. I had refactored some code and added dispatchEvent() into an algorithm that analyzes the class/interface files.

This is a recursive loop in a way becasue the methods were calling eachother. This thing that was different is I have a fileCursor and and fileLength property in the class that acts as a stack in a way looping through an oridnal array of File objects.

Once I added the dispatchEvent() method I suddenly got the StackOverflow #1023 error. I couldn't figure out what I had changed to make it do this.

Well I posted on flexcoders and Gordon Smith answered. He first thought looking at my stack trace that it was an infinate loop. I knew it's not and I wrote some more info on my problem. He then talked to the AS3 team and told me this.

I got more info from the AS3 team... The Player's stack limit is 128K and can't be changed. When a method calls another method, a stack frame gets created which requires 4 bytes for its size, 4 bytes for the return address, 4 bytes for each parameter, and 4 bytes for each local variable. So if a typical function has 2 parameters and 4 local variables, you could have about 4000 recursive metthod calls.

Well, after reading this, I realized that the dispatchEvent() was the culprit of my problem! Why?

This is the way my mind thinks; I instantly left my mind space oif the actual recusrsive methods I was calling and looked beyond into the framework. THen I said, huh, you know what dispatchEvent() adds A LOT of calls to the internal stack.

Once I took the dispatchEvent() out and did a direct call to the next file analyze method.

Here is my green code that was the problem;

    /**
     *
     * @event a FileManagerEvent
     * @see FileManagerEvent
     */

    private function fileQueueCompleteHandler(event:FileManagerEvent):void
    {
        trace("ComponentDocument::fileQueueCompleteHandler()");
        fileManager.removeEventListener(FileManagerEvent.FILE_QUEUE_LOAD_COMPLETE, fileQueueCompleteHandler);
       
        fileDataQueue = ModelLocator.getInstance().fileManagerModel; // collection of File objects
       
        dispatchEvent(new Event("fileQueueComplete"));
       
        currentFileCursor = 0;
        allFilesListLength = fileDataQueue.length;
       
        // Now the algo has changed. the fileDataQueue now holds File objects that
        // already have their data assigned and have an analyzer (for now).
        // we just need to run through these nad call parseTokens() (FOR NOW)
        analyzeFileQueue();
           
    }

    /**
     * Start the queue that will call parseTokens() on the File objects.
     * I really need to rename the method to analyze().
     */

    protected function analyzeFileQueue():void
    {
        trace("analyzeFileQueue()", currentFileCursor, allFilesListLength)
        if (currentFileCursor == allFilesListLength)
        {
            trace("RETURN")
            onQueueComplete();
            return;   
        }
        analyzeNextFile();
    }

    /**
     *
     */

    protected function analyzeNextFile():void
    {
        trace("analyzeNextFile()")
        var model:FileDataQueue = fileDataQueue;
       
        curFile = File(model.getItemAt(currentFileCursor));
        curFile.baseFilePath = currentClassPath;
        curFile.addEventListener("fileAnalyzeComplete", analyzeNextFileHandler);
       
        // problem
        curFile.analyze();

    }

    /**
     *
     */

    protected function analyzeNextFileHandler(event:Event):void
    {
        curFile.removeEventListener("fileAnalyzeComplete", analyzeNextFileHandler);
        currentFileCursor++;
        analyzeFileQueue();
    }
 

If you look this was the problem;

curFile.addEventListener("fileAnalyzeComplete", analyzeNextFileHandler);

I was adding a 'fileAnalyzeComplete' handler from the File object itself. All I did to solve the problem was take it out and insert;

So after the curFile.analyze(), I just copied the handler's code into this method and did a straight shot into the analyzeFileQueue() method.

Problem solved. I thought I might share this with those who might run into this in the future.

Peace, Mike

One Response to “Flex2 :: StackOverflow #1023”

  1. JabbyPanda Says:

    Thanks for sharing. I took a mental note regarding this matter.

Leave a Reply