Массив, используемый для анимации, не выпускающий изображения. Давление памяти
У меня есть 5 массивов, которые я использую для загрузки и воспроизведения 5 наборов изображений для формирования 5 различных анимаций.
У меня огромные проблемы с памятью. До 500мб. Когда я проверяю их размер в видоискателе, размер изображений за пределами приложения составляет всего около 15 МБ.
Я запустил инструмент памяти во время работы моего приложения;
! [MEMORY Status после загрузки 5 массивов.][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];
Но это не дает мне функциональности, которую я хочу, также проблема памяти все еще присутствовала даже с этим кодом ^
Кто-нибудь знает, в чем может быть проблема, или, если я правильно определил проблему, может кто-нибудь помочь мне решить ее, пожалуйста?
Спасибо.
2 ответа
Я думаю, что вы должны попробовать это: скопировать изображения в пакет, как это:
NSMutableArray *images=[[NSMutableArray
alloc]initwithobjects:@"play_button0000.png",@"xxx.png",,,nil];
И напишите свой анимационный код. Кажется, проблема в том, где вы добавляете изображения в массив.
Просто попробуйте.
Попробуйте это, это работает должным образом и не получает никакой проблемы с памятью также:
// 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];
может быть, это поможет вам.