我的应用程序在iPhone4上崩溃,经常使用5至10分钟。
我在应用程序本身中有一些图像,具有内部SQLite文件,图像名称存储在sqlite表中,并从名称中使用。
还可以通过URL(NSURL)从在线数据库中获取一些图像。使用SDWebImage框架将在线DB图像加载到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/