簡體   English   中英

用於動畫不釋放圖像的數組。 記憶壓力

[英]Array used for animation not releasing images. Memory Pressure

我有5個數組,我用它來加載和播放5組圖像,形成5個不同的動畫。

我有大量的內存問題。 高達500mb。 當我在查找器中檢查它們的大小時,圖像在應用程序之外的大小總共只有大約15mb。

我的應用程序運行時,我運行了記憶儀器;

![已加載5個陣列后的MEMORY狀態。] [1]

此圖顯示了加載五個陣列后的內存。 在陣列運行后,它似乎很明顯地保留了圖像? 或者至少我認為這是問題所在。

這是我用於每個數組的代碼;

//Play Button 1 Animation

NSMutableArray *play1Frames = [[NSMutableArray alloc] initWithObjects:
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0000"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0001"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0002"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0003"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0004"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0005"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0006"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0007"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0008"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0009"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0010"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0011"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0012"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0013"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0014"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0015"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0016"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0017"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0018"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0019"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0020"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0021"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0022"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0023"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0024"] ofType:@"png"]],
               [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"play_button0025"] ofType:@"png"]],
               nil];
play1Image.animationImages = play1Frames;
play1Image.animationDuration = 3;
play1Image.animationRepeatCount = 1;
play1Frames = nil;

我想用這個代碼做動畫,我試過這個代碼;

UIImage* animatedImage = [UIImage animatedImageNamed:@"Anim" duration:20];

但它沒有給我我想要的功能,即使使用這個代碼,內存問題仍然存在^

有沒有人知道問題可能是什么,或者如果我已經正確識別出問題,任何人都可以幫我修復它嗎?

謝謝。

嘗試這個,它正常工作,也沒有任何內存問題:

// Load images
NSArray *imageNames = @[@"play_button0000.png", @"play_button0001.png", @"play_button0002.png", @"play_button0003.png",@"play_button0004.png", @"play_button0005.png", @"play_button0006.png", @"play_button0007.png",@"play_button0008.png", @"play_button0009.png", @"play_button0010.png", @"play_button0011.png",@"play_button0012.png", @"play_button0013.png", @"play_button0014.png",
                        @"play_button0015.png",@"play_button0016.png", @"play_button0017.png", @"play_button0018.png", @"play_button0019.png",@"play_button0020.png", @"play_button0021.png", @"play_button0022.png", @"play_button0023.png",@"play_button0024.png",
                        @"play_button0025.png"];
NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
    [images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];

}
 // Normal Animation
animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320,480)];
animationImageView.animationImages = images;
animationImageView.animationRepeatCount=1;
animationImageView.animationDuration = 3;
[self.view addSubview:animationImageView];
[self.view sendSubviewToBack:animationImageView];

可能它會幫助你。

我想你應該試試這個:像這樣將圖像復制到包中:

NSMutableArray *images=[[NSMutableArray   
alloc]initwithobjects:@"play_button0000.png",@"xxx.png",,,nil]; 

並編寫動畫代碼。 問題似乎是您將圖像添加到陣列的位置。

試試吧。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM