5 Replies Latest reply on Aug 13, 2010 3:49 PM by Flex harUI

    Flex in-memory variables expire after duration????

    code_away Level 1

      In flex, do in-memory variables expire after a certain duration, like after a number of hours?? The reason why I ask is because I have a Flex app that works great, but maybe once a week, my web application (codeignitor , mysql) throws an error that my variable cannot be null. What's strange is that this variable, ClientID, should never be null because it's assigned as the time of login and stored as a variable in Flex. Each client-user has a unique ClientID, which ultimately is used to partition the client's data in a table.

       

      In Flex, my variable is declared as follows:

       

      [Bindable]

       

      public var CLIENT_ID:String; //assigned via HTTP post at the time of login.

       

      ------------------------------------------------

      Apache Logs
      User logs In:
      66.XXX.XX.XXX - - [06/Aug/2010:06:02:15 -0700] "GET /login HTTP/1.1" 200 3853 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB0.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"


      Error is thrown hours after: 66.XXX.XX.XXX - - [06/Aug/2010:09:11:30 -0700] "POST /AddItem HTTP/1.1" 500 1403 "http://www.domain.com/FlexApp.swf" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB0.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"

       

      CodeIgniter/App Log (ClientID had to be null for this error to throw)
      ERROR - 2010-08-06 09:11:30 --> Query error: Column 'ItemClientID' cannot be null

       

      ------------------------------------------------

      This error occurs very infrequently. For one client, at most once a week and the client logs in maybe twice daily. Also, the system is highly transactional (hundreds of records a week)

       

      One more thing, during the Add transaction, I use parentApplication.CLIENT_ID to get the value when in a popup window. Not sure if that makes a difference:

       

      <mx:TitleWindow showCloseButton="true" close="removeMe()" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="464" height="100%" creationComplete="creationComplete()">

            <mx:HTTPService id="AddItem" url="{parentApplication.webServiceBaseUrl}/AddItem" result="UpdateItemResult(event)" useProxy="false" method="POST" fault="mx.controls.Alert.show(event.fault.message)" showBusyCursor="true" resultFormat="text">

                  <mx:request xmlns="">

                        <ClientID>{parentApplication.CLIENT_ID}</ClientID>

                        <ItemDescription>{txtDescription.text}</ItemDescription>

                        . . .

                  </mx:request>

            </mx:HTTPService>

       

      Any tips/suggestions would help.

       

      Thanks,

      Code_away

        • 1. Re: Flex in-memory variables expire after duration????
          Flex harUI Adobe Employee

          There is no expiration for objects.  However, keep in mind that the runtime

          uses a garbage collection that is synchronous and not guaranteed to

          complete.  That means that when all references to something are removed and

          that thing should be garbage collected, there is a chance that it won't get

          garbage collected for a while.  There is a small chance that is what is

          going on.

           

          There is also chance that a memory leak is causing code to run unexpectedly.

           

          Let's say you have a session object with a clientId property that is

          listening for changes to a valueobject and sends the changes to a server.

           

          By listening to a valueobject, the valueobject actually has a strong or weak

          reference to the session object depending on how you set it up.

           

          Now let's say you try to destroy the session object but the value object

          stays around.  You might null out the app's reference to the session object

          and set its clientId to null, but if you forget to remove the listener to

          the value object or if you used a weak reference listener and thought you

          don't have to clean it up (which is true, it will eventually go away), the

          problem is that if the valueobject gets modified before the sessionobject

          gets garbage collected, the old session object will get notified and call

          the server with a null clientId.

          • 2. Re: Flex in-memory variables expire after duration????
            code_away Level 1

            Thanks for feedback.

             

            In my case, I'm sending the data via HTTP post and not utilizing value objects (see example). In the popup window, I reference parentApplication.CLIENT_ID, which never changes after the user logs in. If say the user leaves this popup window open for 2 hours, could that exacerbate the problem, as you described? Sorry if my question is off base - I'm not a expert on Flex memory arch & management.

            • 3. Re: Flex in-memory variables expire after duration????
              Flex harUI Adobe Employee

              It shouldn't matter.  You could write a set function for CLIENT_ID and watch

              for it to go null and report the call stack at the time.

               

              I did note that you are using the CLIENT_ID variable but the error was about

              ItemClientID.  Are you sure they are the same and directly passed from the

              request handler to the DB or could there be some server code that turns it

              into null?

              • 4. Re: Flex in-memory variables expire after duration????
                code_away Level 1

                Thanks again.

                 

                CLIENT_ID (in flex) maps to ItemClientID in the application and database. This column essentially identifies which client owns the record. No where in the application ItemClientID is set it to null. I do, however, see where I properly catch the exception but don't exit the function/transaction properly, and as result, execution flow continues. This would explain why I get a database error message.

                 

                I'll need to do further debugging. As you would imagine, it will be difficult since it happens so infrequently and can't reproduce locally.

                • 5. Re: Flex in-memory variables expire after duration????
                  Flex harUI Adobe Employee

                  That's when I would consider adding diagnostics to the app.  If you set

                  -verbose-stacktraces=true in the compiler, the SWF will contain line number

                  information.  Then if you change your CLIENT_ID var to a set function you

                  can do something like this:

                   

                      public function set CLIENT_ID(value:String):void

                  {

                      if (value == null || value =="")

                      {

                          Alert.show(new Error().getStackTrace(), "Please Send To Me", this,

                  ALERT_OK);

                      }

                  }

                   

                  That would show you the code path that sets it to null.

                  1 person found this helpful