3 Replies Latest reply on Mar 13, 2013 12:51 AM by Darryn Campbell

    Is Memory Module supported on MC75 Windows Devices?

      Hi,

       

      I was trying to use Memory Module API on MC75 Windows
      devices in order to check if we use and release correctly memory in our app.

       

      Our application using RhoElements 2.2.1.12 version.

       

      I tried the following code in a ruby controller:

       

        if !System.get_property('is_emulator')

             mem = Memory.getMemoryStats()

             RhoLog.info("Memory", " mem=" + mem.to_s)

           memThreshold= Memory.lowMemThreshold

        end

       

      For Memory.getMemoryStats I got in a log just false. For Memory.lowMemThreshold it just hangs on it.

       

      I 03/08/2013 10:55:42:000 65da84a6     Core::LoadPlugin| Memory

      I 03/08/2013 10:55:42:000 65da84a6    Abstract::Preload| First call

      I 03/08/2013 10:55:42:000 65da84a6 Core::CSync::RegisterCallback| Registered Callback

      E 03/08/2013 10:55:42:000 858d03b6               Memory| mem=false

       

      Does Memory.getMemoryStats returning false means that it is not supported on MC75?

       

      If anybody have snippet of code for correct usage of Memory module functions ruby version?

       

       

      Thank you.

        • Re: Is Memory Module supported on MC75 Windows Devices?
          Robert Galvin

          try logging an actual property of the result instead of the whole object:

           

          if !System.get_property('is_emulator')

                 mem = Memory.getMemoryStats()

                 RhoLog.info("Memory", " mem=" + mem["totalMemory"])

           

              

          end

           

          Also

          Can you try it via Javascript and see if you see any results:

           

          <HTML>
              <HEAD>
              <TITLE>memory Notification</TITLE>
              <META HTTP-EQUIV="memory" content="memoryEvent:url('javascript:getMemory(%json);')">            
              </HEAD> 
              <SCRIPT type="text/javascript">
              function getMemory(jsonObject)
              {
                  alert("Total Memory: " + jsonObject.totalMemory + "KB, Avail Memory: " + jsonObject.availMemory + "KB");        
                  memory.lowMemThreshold  = jsonObject.totalMemory / 10;
                  memory.memoryEvent = "onLowMemory(%json);";     
              }   
              function onLowMemory(jsonObject)
              {
                  alert("The device is running low on memory, only " + jsonObject.availMemory + "KB is left on the device");          
              }   
              </SCRIPT>
              <BR><BR><INPUT type="button" value="GetMemory" onclick="memory.getMemoryStats();">
          </HTML>
          
          1 of 1 people found this helpful
            • Re: Is Memory Module supported on MC75 Windows Devices?

              Thank you for your reply.

               

              I tried both. Ruby code got an error in this line:

               

              I 03/12/2013 16:23:45:000 a481999e     Core::LoadPlugin| Memory

              I 03/12/2013 16:23:45:000 a481999e    Abstract::Preload| First call

              I 03/12/2013 16:23:45:000 a481999e Core::CSync::RegisterCallback| Registered Callback

              E 03/12/2013 16:23:45:000 e5953372               Memory| after getting mem obj

              I 03/12/2013 16:23:45:000 e5953372                  APP| App error: undefined method `[]' for false:FalseClass  apps/app/Login/login_controller.rb:58:in `authenticate_callback'

              lib/rho/rhocontroller.rb:104:in `serve' lib/rho/rhoapplication.rb:248:in `serve' lib/rho/rho.rb:883:in `serve'

              I 03/12/2013 16:23:45:000 e5953372           HttpServer| GC Start.

              I 03/12/2013 16:23:45:000 e5953372           HttpServer| GC End.

              E 03/12/2013 16:23:45:000 04adec7e                  Net| An error occured connecting to the server: 500 returned.

              T 03/12/2013 16:23:45:000 04adec7e                  Net| Server response:         <html>

                          <head>

                              <meta name="viewport" content="width=320"/>

                          </head>

                          <body>

                              <h2>Server Error</h2>

                              <p>

              Error: undefined method `[]' for false:FalseClass<br/>Trace: <br/>apps/app/Login/login_controller.rb:58:in `authenticate_callback'<br/>lib/rho/rhocontroller.rb:104:in `serve'<br/>

              lib/rho/rhoapplication.rb:248:in `serve'<br/>lib/rho/rho.rb:883:in `serve'   </p>   

                          </body>

                      </html>

               

              Javascript returned me undefined  :-(

               

              It looks like it's not supported... :-(

                • Re: Is Memory Module supported on MC75 Windows Devices?
                  Darryn Campbell

                  Memory.getMemoryStats() is not a blocking call that returns a value, it relies on you having predefined a memoryEvent callback:

                   

                  def myFunc
                       Memory.memoryEvent = url_for(:action => :memory_event_callback)
                       # Retrieve the current statistics
                       Memory.getMemoryStats
                       # Be notified when my memory drops below 1MB
                       Memory.lowMemThreshold = '1024'
                  end
                  
                  def memory_event_callback
                       puts "Memory Event #{@params}"
                  end
                  

                   

                  Please bear in mind I haven't verified the above however!

                   

                  Thanks.