UIImageView Animation uses huge amounts of memory

Discussion in 'iOS Programming' started by wlh99, Aug 31, 2009.

  1. wlh99 macrumors 6502

    Joined:
    Feb 7, 2008
    #1
    I have a 40 frame animation. Each frame is 24kb for a total of 960kb.
    I load these into an Array and Animate in a UIImageView. 6MB of General Objects are allocated and my application ultimately crashes.

    6MB is a lot of memory for an animation of less then 1MB. Is there another way to do animations that uses less memory?
     
  2. wlh99 thread starter macrumors 6502

    Joined:
    Feb 7, 2008
    #2
    Anyone? In Instruments when I start animating an additional 20MB of physical memory is taken, and it is released when I stop animating. This seems wrong when the animation itself is less than 1 MB.

    This code demonstrates it.

    Code:
    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
        
        [window makeKeyAndVisible];
    	int i;
    	animationArray = [NSMutableArray arrayWithCapacity:39];
    	[animationArray retain];
    	NSString* rPath = [[NSBundle mainBundle] resourcePath];	
    	NSString*  sPath;
    	
    	for (i=1;i<39;i++) {
    		NSLog(@" interation %d",i);
    		NSLog(@"rPath %@",rPath);
    		sPath = [NSString stringWithFormat:@"%@/LIE2me%02d.jpg",rPath,i];
    		
    		
    		NSLog(@"%@",sPath);
    		
    		
    		UIImage *imgTemp = [UIImage imageWithContentsOfFile:sPath];
    		[animationArray addObject:imgTemp];
    		
    	}
    	
    	NSLog(@"animation count = %d",[animationArray count]);
    	[IV setAnimationImages:animationArray];
    	[IV startAnimating];
    	
    }
    
     
  3. wlh99 thread starter macrumors 6502

    Joined:
    Feb 7, 2008
    #3
    OK. I don't get this.

    Based on the code above. Testing on a real device.

    Physical Memory used stays about 50MB. Physical Memory Free steadily drops to zero. Shouldn't these inversely relate to each other?

    If I stop the animation, the memory is freed, if I start it again it starts dropping again. Leak? In UIImageView? Instruments doesn't find them.
     

Share This Page