我的应用程序在 iPhone4 上因频繁使用 5 到 10 分钟而崩溃。
我在应用程序本身中有一些图像,有内部 SQLite 文件,图像名称存储在 sqlite 表中并从名称中使用。
还可以通过 url (NSURL) 从在线数据库中获取一些图像。在线数据库图像使用 SDWebImage 框架加载到 UIImageView 中。但仍然收到“收到内存警告”并且应用程序被终止
我用仪器检查了它显示图像获取更多数据并导致崩溃
从数据库中获取图像名称数组并将图像加载到 UICollectionViewCell 中的 UIImageView
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell1 = [self->collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
for (UIImageView *lbl in cell1.contentView.subviews)
{
if ([lbl isKindOfClass:[UIImageView class]])
{
[lbl removeFromSuperview];
}
}
imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, cell1.frame.size.width, cell1.frame.size.width)];
imgView.backgroundColor = CLEAR_COLOR;
imgView.contentMode = UIViewContentModeScaleAspectFit;
UIImage *imv = [UIImage imageNamed:(NSString *)mArray_FeatIcon[indexPath.item]];
imgView.image = imv;
[cell1.contentView addSubview:imgView];
imv = nil;
return cell1;
}
uicollectionView中的Weburl加载图像
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell1 = [cvGallery dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
for (UIImageView *lbl in cell1.contentView.subviews)
{
if ([lbl isKindOfClass:[UIImageView class]])
{
[lbl removeFromSuperview];
}
}
UIImageView * imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, cell1.frame.size.width, cell1.frame.size.height)];
imgView.backgroundColor = [UIColor clearColor];
NSString *urlString = [[NSString stringWithFormat:@"%@",mArrThumbUrl[indexPath.item]] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[imgView setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"logo.png"]];
[cell1.contentView addSubview:imgView];
return cell1;
}
由于声誉低,无法添加乐器的屏幕截图。提前致谢。
最佳答案
这可能是由于 iPhone 中的内存管理泄漏所致。请引用本教程链接并检查 Instruments 中的 NSZombies。
按照此链接-> 我认为这非常有用。
http://www.raywenderlich.com/23037/how-to-use-instruments-in-xcode
关于ios - 应用程序因内存压力而终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32759089/