1

I am trying to display Image using UIPageViewController, using the sample code from apple and replacing it with the new photo Kit: PHAsset https://developer.apple.com/library/ios/samplecode/MyImagePicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010135 When i swiping the photo with PHImageManagerMaximumSize, i found that after 50 photos, the app will crash showing "assetsd interrupted or died". But if i request a smaller target size(same size as screen), the crash is becoming unlikely. I am wondering if it is a memory leak somewhere in my app or there is something wrong in the rendering system ? Seems the compression and uncompression are using a lot of pages. Could anyone help me to have a look?

- (void)displayImage:(PHAsset*)asset
{
 [self.imageView removeFromSuperView]
 self.imageView = nil;
 [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFit options:nil resultHandler:^(UIImage *result, NSDictionary *info) {

        self.imageView = [[UIImageView alloc] initWithImage:result];
        self.imageView.contentMode = UIViewContentModeScaleAspectFit;
        // self is a scrollView    
        [self addSubview:self.imageView];
    }];
}

------ log in console ----------

2015-02-27 22:35:20.613 XXX [2831:145514] ImageViewController, -[ImageViewController didReceiveMemoryWarning] 2015-02-27 22:35:22.111 XXX [2831:145558] Connection to assetsd was interrupted or assetsd died

------- crash logs ---------

Free pages: 1361 Active pages: 26954 Inactive pages: 13499 Speculative pages: 40 Throttled pages: 0 Purgeable pages: 0 Wired pages: 59258 File-backed pages: 11321 Anonymous pages: 29172 Compressions: 6474001 Decompressions: 704086 Compressor Size: 151510 Uncompressed Pages in Compressor: 212409 Page Size: 16384 Largest process: iGather

Processes Name | | CPU Time| rpages| purgeable| recent_max| lifetime_max| fds | [reason] | (state)

assistant_servic <97db64323f2e364ea0af497680126850> 0.485 1451 0 - 4111 50 [vm-pageshortage] (daemon) (idle) medialibraryd <6a42c5e99f153b4baa0992e9902bee82> 0.296 1037 0 - 2072 50 [vm-pageshortage] (daemon) (idle) WirelessRadioMan 0.077 285 0 - 890 50 [vm-pageshortage] (daemon) (idle) awdd <58036e1703903ee798a8803de204c300> 0.070 402 0 - 1043 50 [vm-pageshortage] (daemon) (idle) assetsd <276c271c5b073f58bf87c49abf22b264> 0.188 679 0 - 1907 50 [vm-pageshortage] (daemon) (idle) seld <18863ab32c7634d5b7f200821acffd06> 0.030 193 0 - 696 50 [vm-pageshortage] (daemon) passd <56971afa88b53f05a37688cad47b4160> 0.243 630 0 - 2384 50 [vm-pageshortage] (daemon) nfcd <59e46913bec838d989d5bed82cb05791> 0.023 184 0 - 624 50 [vm-pageshortage] (daemon) biometrickitd <71607be9393c366eb1bbe281256fde77> 0.141 273 0 - 841 50 [vm-pageshortage] (daemon) debugserver 0.306 207 0 - 629 50 [vm-pageshortage] (daemon) MobileMail <4b48abd990e93dbea47db1cbf328da9e> 0.957 1496 0 - 4063 50 [vm-pageshortage] (resume) (continuous) lsd 1.213 364 0 - 1032 50 [vm-pageshortage] (daemon) tccd 0.132 238 0 - 593 50 [vm-pageshortage] (daemon) kbd <8c8bded31cf73db2b44aa996c0e90921> 0.116 344 0 - 1447 50 [vm-pageshortage] (daemon) iGather 3.610 23061 0 - 21099 50 [vm-pageshortage] (frontmost) (resume) ...

helloJosh
  • 11
  • 2

1 Answers1

2

You should definitely use Instruments to confirm this, but I've found that even with ARC you have to be conservative with memory usage when processing a batch of photos.

Like you I wanted to provide the user with the highest possible quality image so they can zoom in and examine the photo in detail. I display N photos in a grid. I found that even when getting rid of all references to those assets, they're not freed before the next set of N is loaded. I just had to cut my memory usage in half so that brief transition where N * 2 are in memory didn't crash my app.

Of course, if your memory usage is increasingly monotonically then you probably do have surviving references to those images somewhere in your code. Again, Instruments.

Duc
  • 487
  • 1
  • 7
  • 15
  • Thanks for you answer, i think i have found the reason. It is because the view controller the PageViewController created is no released. Yes, like you said, Instruments. – helloJosh Mar 09 '15 at 05:48