> On Sep 22, 2020, at 1:46 PM, Eric Lee via Cocoa-dev 
> <cocoa-dev@lists.apple.com> wrote:
> 
>> I don't have a good answer, but I think this may be more that UIImage caches 
>> the images, not UIImageView. Maybe you can find something in UIImage's 
>> docs/headers?
> 
> I think you may be on to something.  This WWDC 
> <https://developer.apple.com/videos/play/wwdc2018/219> session covers 
> optimizing UIImage performance and has some info on what UIImage caches.
> 
> How are you creating the UIImage?  Are you retaining the UIImage anywhere 
> outside of the UIImageView? 


The path of UIImage creation is as follows:

- For each manually-initiated processing pass of the app, a standard set of 12 
JPG files is written to the sandbox using the OpenCV::imwrite() function, which 
creates a JPG from data values. The files have fixed filenames.

- When all 12 JPG files for a pass are written, I then use the following code 
snippet to create the UIImages and display them on the main UIImageView:

    NSMutableArray *uiImagesArray = [NSMutableArray new];
    for (NSString *file in [[NSFileManager defaultManager] 
contentsOfDirectoryAtPath:self.sandboxPath error:NULL]) {
        if ([file.pathExtension isEqualToString:@"jpg"]) {
            UIImage *tempImage = [UIImage imageNamed:jpgFilename];
            if (tempImage) [uiImagesArray addObject:tempImage];
        }
    }
    UIImage *allAGFAImages = [UIImage animatedImageWithImages:uiImagesArray 
duration:20.0];
    self.imageView.image = allAGFAImages;

- When a new pass of the app is run, the sandbox contents are deleted (see 
below), the uiImagesArray variable is set to nil, and the new JPG files are 
written, using the same filenames as before. Note that I do not set each 
UIImage in the array explicitly to nil.

    [[NSFileManager defaultManager] removeItemAtURL:[NSURL 
fileURLWithPath:[self.sandboxPath stringByAppendingPathComponent:file]] 
error:&error];

- If I add a uniquing string to the filenames for each pass, the problem does 
not present itself. Otherwise the original (old) cached image contents are 
displayed until the app is restarted.

- I don't retain the UIImages anywhere other than adding them to the array in 
the code snippet above.

-Carl

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to