7 Replies Latest reply on Nov 23, 2011 10:06 AM by John Hawkinson

    [JS CS5] possible memory leak problem with dialog box in event handler

    richardh6 Level 1

      Hello,

       

      I am having a very difficult problem.

       

      I have attached a script as an event handler to a menu item, using a menu installation script I wrote based on one by Marc Autret. My version of the menu installation script attaches a bunch of event handlers all at the same time, to different menu actions.

       

      What the event handler I'm having a problem with does is prompt the user for a URL, and then applies the URL as a hyperlink to the text selection, with our house style for how the URL should look.

       

      The problem is this:

       

      1. All of the other installed menu actions work fine, except for this one.

       

      2. The URL-adding script works fine, when you run it directly from the script menu.

       

      3. The combination of #1 and #2 (using the URL-adding script by running it as an event handler from the Edit menu) crashes InDesign. But not until after the URL-adding script has finished, and completed everything it was supposed to do!

       

      4. When I comment out the user-input section of the URL-adding script, so that instead of saying

       

      userInput = myDisplayDialog();
      

       

      it says

       

      userInput = "http://thisworks.com";   // userInput = myDisplayDialog();
      

       

      it works fine as an event handler.

       

      So obviously it's a problem with the dialog box, but only when the URL-adding script is run as an event handler. My first guess is that it's some kind of memory leak, but I think I'm following the .destroy() pattern the way I've seen it elsewhere.

       

      Has anybody experienced anything like this before?

       

      I can provide all the relevant scripts if necessary, but they're pretty convoluted. The most important one is the user input function. Here it is:

       

       

      var myDisplayDialog = function( defaultText ) {
        
          var defaultText = defaultText || "";
          
          var myDialog = app.dialogs.add({
              name: "Type in a URL"
          });
          
          var myOuterColumns = [];
          var myInnerColumns = [];
          var myOuterRows = [];
          var myBorderPanels = [];
          var myTextEditboxes = [];
          var myInput;
          
          myOuterColumns[0] = myDialog.dialogColumns.add();
          myOuterRows[0] = myOuterColumns[0].dialogRows.add();
      
      
          myBorderPanels[0] = myOuterRows[0].borderPanels.add();
          myInnerColumns[0] = myBorderPanels[0].dialogColumns.add();
          myInnerColumns[0].staticTexts.add({
              staticLabel: "URL:"
          });
          
          myInnerColumns[1] = myBorderPanels[0].dialogColumns.add();
              
          myTextEditboxes[0] = myInnerColumns[1].textEditboxes.add({
               minWidth: 300,
               editContents: defaultText ? defaultText : "http://"
          });
          
          var myResult = myDialog.show();
          var myInput = myTextEditboxes[0].editContents;
          
          myDialog.destroy();
      
          if (myResult == false) {
                exit();
          }
          
          return myInput;
      
      }