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

iOS: UI.imageView - changing image property results in memory leak

    Details

      Description

      Problem

      I have an ImageView, clicking on the right, i want to change its image to the next image, clicking to the left, to the previous image, for browsing 50 images.

      Changing the image property of the imageView causes a memory leak which never recovers when using 1.8.0.1.

      Note that there is no memory leak when using 1.7.5.

      Test case

      app.js

      (function(){ 
      	var screenWidth = Ti.Platform.displayCaps.platformWidth; 
      	Ti.UI.setBackgroundColor('#000'); 
      	
      	var win = Ti.UI.createWindow({ 
      		backgroundColor:'#000000', 
      		fullscreen: true 
      	}); 
      	
      	win.open(); 
      	
      	var currentImage=1; 
      	var max = 20; 
      	
      	var myImageView = Ti.UI.createImageView({ 
      		image: 'img/'+currentImage+'.jpg', 
      		touchEnabled:false 
      	}); 
      	win.add(myImageView); 
      	
      	function setImage(view, image){ 
      		view.image = 'img/'+image+'.jpg'; 
      	} 
      	
      	win.addEventListener('click', function(e){ 
      		if(e.x > (screenWidth/2)){ 
      		currentImage++; 
      		if (currentImage>max) { 
      		currentImage=1; 
      		} 
      		} else { 
      		currentImage--; 
      		if(currentImage<1){ 
      		currentImage=max; 
      		} 
      		} 
      		
      		setImage(win.children[0], currentImage); 
      		
      		Ti.API.info("memory = "+Ti.Platform.availableMemory); 
      	}); 
      	
      	setInterval(function() {
      		win.fireEvent('click');
      	}, 100);
      })(); 
      

      Logs

      console using 1.8.0.1

      [INFO] One moment, building ...
      [INFO] Titanium SDK version: 1.8.0.1 (12/22/11 13:09 fbdc96f)
      [INFO] iPhone Device family: universal
      [INFO] iPhone SDK version: 5.0
      [INFO] iPhone simulated device: iphone
      [INFO] Performing full rebuild. This will take a little bit. Hold tight...
      [INFO] Skipping JS compile, running from simulator
      [INFO] Performing clean build
      [INFO] Launching application in Simulator
      [INFO] Launched application in Simulator (11.92 seconds)
      [INFO] Found 5.0 patch installed
      [INFO] Application started
      [INFO] ImageViewTest/1.0 (1.8.0.1.fbdc96f)
      [INFO] memory = 3222.25
      [INFO] memory = 3208.1328125
      [INFO] memory = 3196.17578125
      [INFO] memory = 3184.48828125
      [INFO] memory = 3172.92578125
      [INFO] memory = 3159.390625
      [INFO] memory = 3145.64453125
      [INFO] memory = 3133.76171875
      [INFO] memory = 3125.4140625
      [INFO] memory = 3124.609375
      [INFO] memory = 3112.7421875
      [INFO] memory = 3100.7890625
      [INFO] memory = 3089.1484375
      [INFO] memory = 3074.5859375
      [INFO] memory = 3062.8671875
      [INFO] memory = 3050.9921875
      [INFO] memory = 3039.40625
      [INFO] memory = 3027.44921875
      [INFO] memory = 3015.515625
      [INFO] memory = 3000.921875
      [INFO] memory = 3000.96875
      

      console using 1.7.5

      [INFO] One moment, building ...
      [INFO] Titanium SDK version: 1.7.5
      [INFO] iPhone Device family: universal
      [INFO] iPhone SDK version: 5.0
      [INFO] iPhone simulated device: iphone
      [INFO] Performing full rebuild. This will take a little bit. Hold tight...
      [INFO] Skipping JS compile, running from simulator
      [INFO] Performing clean build
      [INFO] Launching application in Simulator
      [INFO] Launched application in Simulator (12.99 seconds)
      [INFO] Found 5.0 patch installed
      [INFO] Application started
      [INFO] ImageViewTest/1.0 (1.7.5.ab20af7)
      [INFO] memory = 3165.79296875
      [INFO] memory = 3153.82421875
      [INFO] memory = 3154.390625
      [INFO] memory = 3154.45703125
      [INFO] memory = 3154.53515625
      [INFO] memory = 3154.6015625
      [INFO] memory = 3154.66015625
      [INFO] memory = 3152.76953125
      [INFO] memory = 3152.890625
      [INFO] memory = 3152.98046875
      [INFO] memory = 3153.0703125
      [INFO] memory = 3157.1953125
      

      Workaround

      Although it's depreciated, using the url instead of image property resolves the issue.

      Discussions

      Q&A: changing image of an imageview does not free memory

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                stephentramer Stephen Tramer
                Reporter:
                cecileadam Cécile Adam
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

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

                    Git Integration