{"id":5601,"date":"2014-04-03T21:36:31","date_gmt":"2014-04-03T21:36:31","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/03\/received-memory-warning-in-uicollectionview-ios-7-collection-of-common-programming-errors\/"},"modified":"2014-04-03T21:36:31","modified_gmt":"2014-04-03T21:36:31","slug":"received-memory-warning-in-uicollectionview-ios-7-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/03\/received-memory-warning-in-uicollectionview-ios-7-collection-of-common-programming-errors\/","title":{"rendered":"Received memory warning in UICollectionView iOS 7-Collection of common programming errors"},"content":{"rendered":"<p>I am using UICollectionView to show all the images available in my library using assets, its displaying all the images but when I scroll up and down many times , I receive a memory issue in the device and after some time it gets crashed saying <strong>CRASHED DUE TO MEMORY PRESSURE<\/strong> code used are as follows<\/p>\n<p>creates here the collectionview and settings its delegate<\/p>\n<pre><code>UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];\nallPhotosCollectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(5, 5, 310, 481)collectionViewLayout:layout];\n[allPhotosCollectionView setDelegate:self];\n[allPhotosCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@\"Cell\"];\n[allPhotosCollectionView setDataSource:self];\n[self.view addSubview:allPhotosCollectionView];\n<\/code><\/pre>\n<p>delegate methods<\/p>\n<pre><code>- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section\n{\nreturn [allImageArray count];\n}\n- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView\n{\nreturn 1;\n}\n- (CGSize)collectionView:(UICollectionView *)collectionView layout:       (UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath   *)indexPath\n{\nreturn CGSizeMake(95, 100);\n}\n\n- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{\nNSString *identifier = @\"Cell\";\nUICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];\n\/\/ allimageArray has the Assest URL fo the images\nNSURL *aURL=[[NSURL alloc]initWithString:[NSString stringWithFormat:@\"%@\",[allImageArray objectAtIndex:indexPath.row]]];\n[assestLibrary assetForURL:aURL resultBlock:^(ALAsset *asset)\n {\n     UIImage  *copyOfOriginalImager = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage] scale:0.5 orientation:UIImageOrientationUp];\n     UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 90, 90)];\n     NSData *imageData;\n     imageData=UIImageJPEGRepresentation(copyOfOriginalImager, 0.4);\n     [imageView setImage:[UIImage imageWithData:imageData]];\n  [cell.contentView addSubview:imageView];\n  }\n        failureBlock:^(NSError *error)\n  {\n     \/\/ error handling\n     NSLog(@\"failure-----\");\n    }];\n  return cell;\n  }\n<\/code><\/pre>\n<p>I am facing many problems in iOS 7 , app crash due to memory pressure , please explain that too<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am using UICollectionView to show all the images available in my library using assets, its displaying all the images but when I scroll up and down many times , I receive a memory issue in the device and after some time it gets crashed saying CRASHED DUE TO MEMORY PRESSURE code used are as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5601","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5601"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5601\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}