Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-16450

Android: imageAsResized is leaking memory

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Low
    • Resolution: Fixed
    • Affects Version/s: Release 4.1.0
    • Fix Version/s: Release 5.1.0
    • Component/s: Android
    • Labels:
    • Environment:

      Titanium SDK 4.1.0.GA
      Android OS 4.4 Device: Nexus 4
      Android OS 4.4.2 Device: LG G2

    • Story Points:
      8
    • Sprint:
      2015 Sprint 19 SDK

      Description

      Problem Description

      When using the imageAsResize function in blob, it will start eventually to fail with a warning message about no more memory available.

      Test Code

        var count = 0;
       
      var win = Ti.UI.createWindow({
          backgroundImage : 'b1.png',
          layout : 'vertical'
      });
      var closeBtn = Ti.UI.createButton({
          title : 'close',
          top : '44dp',
      });
      var resizeBtn = Ti.UI.createButton({
          title : 'resize: ' + count,
          top : '20dp',
      });
      var imageView = Ti.UI.createImageView({
          width : '200dp',
          height : '200dp',
      });
       
      //--
      win.add(closeBtn);
      win.add(resizeBtn);
      win.add(imageView);
       
      //--
       
      resizeBtn.addEventListener('click', function() {
          var f = Ti.Filesystem.getFile('b1.jpg');
          var blob = f.read();
          f = null;
          win.remove(imageView);
          imageView.view = null;
          imageView = null; 
          imageView = Ti.UI.createImageView({
          width : '200dp',
          height : '200dp',
      	});
          imageView.image = blob.imageAsResized(960, 960);
          blob = null;
          win.add(imageView);
          count++;
          resizeBtn.title = 'resize: ' + count;
      });
      closeBtn.addEventListener('click', function() {
          win.close();
      });
       
      win.open();
      

      Attachments

      Check the attachments for b1.jpg

      Steps to reproduce

      1. Create mobile project (classic titanium)
      2. Copy-Paste the code from the testcase into app.js
      3. Copy bg1.jpg into Resources directory
      4. Deploy into device
      5. Click in resize until the image doesn't appear anymore.

      Extra info

      when the image doesn't appear anymore, you will see a message in the console saying:

       
      [ERROR] :  TiBlob: (KrollRuntimeThread) [3227,231234] Unable to resize the image. Not enough memory: null
      [ERROR] :  TiBlob: java.lang.OutOfMemoryError
      [ERROR] :  TiBlob: 	at android.graphics.Bitmap.nativeCreate(Native Method)
      [ERROR] :  TiBlob: 	at android.graphics.Bitmap.createBitmap(Bitmap.java:809)
      [ERROR] :  TiBlob: 	at android.graphics.Bitmap.createBitmap(Bitmap.java:786)
      [ERROR] :  TiBlob: 	at android.graphics.Bitmap.createBitmap(Bitmap.java:718)
      [ERROR] :  TiBlob: 	at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:594)
      [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.imageAsResized(TiBlob.java:543)
      [ERROR] :  TiBlob: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
      [ERROR] :  TiBlob: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:64)
      [ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:884)
      [ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1107)
      [ERROR] :  TiBlob: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:327)
      [ERROR] :  TiBlob: 	at android.os.Handler.dispatchMessage(Handler.java:98)
      [ERROR] :  TiBlob: 	at android.os.Looper.loop(Looper.java:136)
      [ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
      [INFO] :   I/dalvikvm-heap: Grow heap (frag case) to 182.277MB for 1474561
      

      Q&A Link

      http://developer.appcelerator.com/question/162431/android-memory-leaks

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                msamah Ashraf Abu (Inactive)
                Reporter:
                mpmiranda Mauro Parra-Miranda
                Reviewer:
                Hieu Pham
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-18364
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration