• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Invalidating UIImageView's image cache
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Invalidating UIImageView's image cache


  • Subject: Re: Invalidating UIImageView's image cache
  • From: Mike Abdullah via Cocoa-dev <email@hidden>
  • Date: Wed, 23 Sep 2020 09:34:29 +0100

Correct, this is your issue. Have a read of the docs on +[UIImage imageNamed:]
 They explicitly discuss the cache. This is not the API you want.

Mike.

> On 23 Sep 2020, at 02:12, Eric Lee via Cocoa-dev <email@hidden>
> wrote:
>
> Ah maybe it is the use of `imageNamed:`.  I believe that caches the image
> data in a system cache.  Have you tried `imageWithContentsOfFile:`?
>
> https://developer.apple.com/documentation/uikit/uiimage/1624123-imagewithcontentsoffile
>
>> On Sep 22, 2020, at 16:56, Carl Hoefs <email@hidden> wrote:
>>
>>
>>> On Sep 22, 2020, at 1:46 PM, Eric Lee via Cocoa-dev
>>> <email@hidden> 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 (email@hidden)
>
> 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:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Invalidating UIImageView's image cache
      • From: Carl Hoefs via Cocoa-dev <email@hidden>
References: 
 >Re: Invalidating UIImageView's image cache (From: Eric Lee via Cocoa-dev <email@hidden>)
 >Re: Invalidating UIImageView's image cache (From: Carl Hoefs via Cocoa-dev <email@hidden>)
 >Re: Invalidating UIImageView's image cache (From: Eric Lee via Cocoa-dev <email@hidden>)

  • Prev by Date: Re: Invalidating UIImageView's image cache
  • Next by Date: Re: Invalidating UIImageView's image cache
  • Previous by thread: Re: Invalidating UIImageView's image cache
  • Next by thread: Re: Invalidating UIImageView's image cache
  • Index(es):
    • Date
    • Thread