我试图检查我的仪器中的应用程序内存问题。当我加载应用程序时,我会播放一些声音并在UIImageView中显示一些动画。 为了节省一些内存,我只在需要时才加载声音,当我停止播放时,我将它从内存中释放。内存问题 - 生活与整体 - >应用程序被杀
问题1:
我的应用程序正在使用大约生活内存5.5MB。但总体部分在开始到20MB之后正在增长,然后它正在缓慢增长(大约100kB /秒)。但是,负责图书馆的OpenAL(OAL ::缓冲区),使dyld(_dyld_start)-I我不知道这真的是,和一些其他的东西像ft_mem_qrealloc,CGFontStrikeSetValue,...
问题2:
当整体节大约30MB,应用程序崩溃(被杀害)。 根据我已经读过的有关整体内存的事实,这意味着我的所有分配和释放约为30MB。但我真的不明白这个问题。当我需要一些声音例如我加载它的内存,当我不再需要它时,我释放它。但是这意味着当我加载1MB声音时,此操作会增加2MB的整体内存使用量。我对吗?当我加载10个声音时,我的应用程序崩溃,只是因为我的整体过高甚至生活的事实仍然很低? 我对此很困惑。
有人可以帮我清除它吗?
(我在iOS 5和使用ARC)
一些代码:
创造声音的OpenAL:
MYOpenALSound *sound = [[MyOpenALSound alloc] initWithSoundFile:filename willRepeat:NO];
if(!sound)
return;
[soundDictionary addObject:sound];
播放:
[sound play];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, ((sound.duration * sound.pitch) + 0.1) * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[soundDictionary removeObjectForKey:[NSNumber numberWithInt:soundID]];
});
}
创建与声音AVAudioPlayer:
[musics replaceObjectAtIndex:ID_MUSIC_MAP withObject:[[Music alloc] initWithFilename:@"mapMusic.mp3" andWillRepeat:YES]];
pom = [musics objectAtIndex:musicID];
[pom playMusic];
,并停止和释放它:
[musics replaceObjectAtIndex:ID_MUSIC_MAP withObject:[NSNull null]];
和图像动画: 我加载从大的PNG文件中的图像(这也realated到我的其他话题:https://stackoverflow.com/questions/12223714/memory-warning-uiimageview-and-its-animations) 我有几个的UIImageViews和时间我设置动画阵列来播放动画...
UIImage *source = [[UIImage alloc] initWithCGImage:[[UIImage imageNamed:@"imageSource.png"] CGImage]];
cutRect = CGRectMake(0*dimForImg.width,1*dimForImg.height,dimForImg.width,dimForImg.height);
image1 = [[UIImage alloc] initWithCGImage:CGImageCreateWithImageInRect([source CGImage], cutRect)];
cutRect = CGRectMake(1*dimForImg.width,1*dimForImg.height,dimForImg.width,dimForImg.height);
...
image12 = [[UIImage alloc] initWithCGImage:CGImageCreateWithImageInRect([source CGImage], cutRect)];
NSArray *images = [[NSArray alloc] initWithObjects:image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, image11, image12, image12, image12, nil];
,这阵我只是用简单的喜欢:
myUIImageView.animationImages = images, ... duration -> startAnimating
分享一些代码花花公子 – AppHandwerker