1

I am quite confused in the matter of Memory Utilization. My app crashes after loading a various amount of images (retrieved from Parse.com).

To make this simpler my app consists in showing images of certain categories so this is what I have: First you are presented with a 'PFQueryTableView' you select a 'cell' and are pushed to a 'ScrollView' loaded with 10 'PFImageView' and of course after swiping through the Images of lets say 5 previous cells, my app crashes due to Memory Pressure or Memory Error.

I am using the following code which I believe should help with cached data and not download it on the device:

- (PFQuery *)queryForTable{

PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
query.cachePolicy = kPFCachePolicyNetworkOnly;

return query;

That wouldn't do anything since the memory kept on rising so I tried adding custom cache settings:

- (void)viewDidUnload
{
[super viewDidUnload];

[PFQuery clearAllCachedResults];
}

To delete any data.. after viewing. But when I test the app, the memory utilized just keeps on rising for each cell clicked until it reaches about 550 MB and then crashes...

I also tried releasing my PFImageViews but can't since I am using ARC and it's supposed to do that automatically. So my question is, am I missing something? How do I set it for the images to be viewed without taking up that incredible amount of memory of the device?

Any help would be greatly appreciated! Thanks for you time in reading, and if it is really a basic question I apologize.

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
adriennemhenry
  • 133
  • 1
  • 3
  • 17

2 Answers2

2

Post iOS6, viewDidUnload is deprecated. Docs say "Views are no longer purged under low-memory conditions and so this method is never called" - I'd be surprised if a breakpoint there is ever hit.

Can you explicitly set to nil any object that is no longer required, enabling that memory to be reclaimed?

You may want to switch to a continuously rotating UIScrollView scheme. At any time you have only three images loaded; the previous, the current and the next.

If you swipe left, "left" becomes "current", "current" becomes "right", "right" is discarded and you load a new "left".

If you swipe right, "right" becomes "current", "current" becomes "left", "left" is discarded and you load a new "right".

Here's an old answer I wrote about this with more detail on making the cyclic view controller.

Community
  • 1
  • 1
Adam Eberbach
  • 12,309
  • 6
  • 62
  • 114
  • Thanks for the quick response! I tried the continuous `UIScrollView` before but couldn't figure out how to set the code right since I am using Parse.com backend but I'll give it another try! – adriennemhenry Mar 19 '14 at 05:28
0

kPFCachePolicyNetworkOnly means the opposite of what it seems you are after. It means that the app should never use the cache for the query results, but ALWAYS use the network for downloading images. So, if you've already fetched an image on an earlier attempt, it will still download the image again now.

To achieve what you were meaning to, use kPFCachePolicyCacheThenNetwork. This will force the app to check the cache first, and then fetch it from parse only if not found in the cache.

This setting is to reduce network usage, not memory, so I doubt it will do much for your memory problem.

If you still experience memory issues, consider using a scaled down version of images for browsing, or implement a PageViewController based browser instead.

Marius Waldal
  • 9,537
  • 4
  • 30
  • 44
  • You are right, not much done with the memory. I think I'll have a cleaner outcome with a `UICollectionView`. Thanks for answering! – adriennemhenry Mar 19 '14 at 05:33