2 Replies Latest reply on Mar 24, 2009 2:29 PM by RA-Ross

    Zombie processes workaround

    phdb Level 1
      I’m developing an HTML/JS application on an XP SP3 machine with the latest version of the Air runtime and SDK. ADL regularly and randomly stays in memory after the application terminates. Worse than that, the packaged application acts the same way. When the application is executed 5 times, at least 2 instances stay in memory forever and have to be killed manually through the Task Manager.

      I reproduced the problem with the “hello world” application described in chapter 5 of “Developing Adobe Air 1.5 applications with HTML and Ajax”, and by clicking on the window’s close button.

      I also tried 2 other ways to close “hello world”:
      1) “air.NativeApplication.nativeApplication.exit()”
      2) “window.close()” with Nativeapplication.autoExit = true .
      Same result.

      I finally found a workaround: working with 2 windows.

      The main window (test.html) displays nothing. Its visibility property is set to false in the xml descriptor file. The other parameters remain unchanged.


      Here is the contents of test.html:

      <script src="lib/air/AIRAliases.js" type="text/javascript"></script>
      <script type="text/javascript">
      var html2;

      function loading() {
      var initOptions = new air.NativeWindowInitOptions();
      var bounds = new air.Rectangle(10, 10, 600, 400);
      html2 = air.HTMLLoader.createRootWindow(true, initOptions, true, bounds);
      var urlReq2 = new air.URLRequest("test2.html");

      function exit() {

      var app = air.NativeApplication.nativeApplication;
      app.addEventListener(air.Event.EXITING, exit);
      <body onload="loading();">

      The second window is the real working window and displays the “hello world” message. It intercepts the closing event generated by the close button and send an exiting event handled by the main window. When the main window receives the exiting event, it closes the second window, close itself and terminates the application as Nativeapplication.autoExit is true by default.

      Contents of test2.html

      <script src="lib/air/AIRAliases.js" type="text/javascript"></script>
      <script type="text/javascript">
      function closing() {
      var exitingEvent = new air.Event(air.Event.EXITING, false, true);
      window.nativeWindow.addEventListener(air.Event.CLOSING, closing);
      Hello World

      Now, I have no more zombie processes. ADL and the packaged application always terminate gracefully.

      Did other people encounter the same problem ? Is there another way to solve it?

        • 1. Re: Zombie processes workaround
          jbenson@oper8 Level 2

          I don't think you should have to, but...

          Have you tried using air.NativeApplication.nativeApplication.exit() in your exit function above?

          I would assume that close of the only nativeWindow should exit the application. Perhaps log a bug at:

          • 2. Re: Zombie processes workaround
            RA-Ross Level 1
            Working in Flash here, so the syntax is a little different, but perhaps manually adding a close event listener to the main window would work?

            I've had some luck using the following code which simply attaches an exit instruction to the window close event for the main window... however, the underlying assumption that the main app window is always index 0 troubles me.

            --- Code below (Flash CS4) ---

            NativeApplication.nativeApplication.openedWindows[0].addEventListener(Event.CLOSE, shutdown);

            function shutdown(e:Event) {
            trace("Main window closed; shutting down");