ColonelPanic has asked for the wisdom of the Perl Monks concerning the following question:

Hello All,

I am having a problem with my script causing the interpreter to crash (as in causing a windows error message box) when it exits. This is after all of my code is executed, so apparently it is during the garbage collection or some other cleanup.

I am using some regexes that refer to each other recursively with the experimental (??{}) construct within qr// strings, so my first thought was that this might be causing a circular reference problem of some sort for garbage collection. However, it makes no difference if I undef all of these myself.

Unfortunately, my script is quite long, so I'm not certain where to look. The error started appearing when I added a large segment of code that includes the aforementioned regexes, as well as several recursive functions.

Does anyone have any general insight on what sort of thing would cause a crash like this? Is there a possibility that there is some sort of case with recursion that could cause garbage collection problems? Are the experimental regex features just living up to their name?

Update: Running in the debugger does not shed any light on the situation. In fact, the crash still happens, but when I exit the debugger.

Thanks in advance,
ColonelPanic


When's the last time you used duct tape on a duct? --Larry Wall

Replies are listed 'Best First'.
Re: Interpreter crashes on script exit
by dave_the_m (Monsignor) on May 11, 2004 at 15:24 UTC
    (?{...}) is still quite buggy. If you're using an older version of Perl you could try upgrading to 5.8.4 and see if the problem goes away. Other than that, avoid creating anonmous subs within them, and and avoid lexical vars within them if possible. Some common things that can cause crashes on code exit:

    freeing a deeply nested structure, such as [ 1, [ 2, [ 3, .... ]]]
    a DESTROY method that kicks off some sort of recursion, especially regexp recursion
    anything involving multiple threads

      Thanks for the info. I am using ActivePerl 5.8.3 on Windows, which is their latest. I am not using any embedded code within the regexes, except for some recursive (??{$foo}) type things with a single variable.

      I don't have multiple threads or any OO code, but I do have nested arrays that go 4 or 5 levels deep. I'll take a look at that portion of the code.


      When's the last time you used duct tape on a duct? --Larry Wall
Re: Interpreter crashes on script exit
by bart (Canon) on May 11, 2004 at 18:39 UTC
    Probably this is a long shot...

    I used to suffer a similar behaviour, when I used XML::Parser::Expat directly, thus without going through XML::Parser, if it died without me having a chance to do some cleanup. The problem was indeed that this parser uses circular references internally, and you have to call its release method in order to break these chains. Actually, I suspect one of the reasons for the existence of XML::Parser as a wrapper, is precisely to do this cleanup for you, in case of an error.

    So.... if you have circular references that aren't broken before the final curtain falls, apparently this is what you can expect to happen.

    Are you sure you did indeed break all circular references, if present, by just undeffing the variables? I doubt it.

Re: Interpreter crashes on script exit
by aquarium (Curate) on May 11, 2004 at 15:20 UTC
    run your program with the perl debugger...and check that you're realy getting a condition that eventually exits out of the recursive subs. if it loops recursively without end, it will crash. comment out the regexes and put in their place some valid static value, to see that the regexes are indeed not causing the crash...i doubt they are.
      Thanks for the suggestions. My script successfully executes all of my code. I can break on the exit statement in the debugger and get there with no problems. The recursion is over by this point.

      As for the regexes, they can't be easily replaced with static values, because this will break other code. I might have to go that route anyway if I can't figure out the problem, though.



      When's the last time you used duct tape on a duct? --Larry Wall