Re: Invalidating UIImageView's image cache

2020-09-23 Thread Carl Hoefs via Cocoa-dev
Yes! +[UIImage imageNamed:] was The Caching Culprit™️. I was barking up the 
wrong object (UIImageView).

As per Eric's suggestion I've switch to +[UIImage imageWithContentsOfFile:], 
and now there's no image caching (as per  Mike's suggestion to RTM: "This 
method does not cache the image object". I simply didn't notice/expect the docs 
would comment on that).

Plus my code is much cleaner now as I can stop the flail of uniquing the 
filenames, deleting the sandbox files, etc...

Thanks Eric & Mike!
-Carl



> On Sep 23, 2020, at 1:34 AM, Mike Abdullah  wrote:
> 
> 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  
>> 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  
>>> wrote:
>>> 
>>> 
 On Sep 22, 2020, at 1:46 PM, Eric Lee via Cocoa-dev 
  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 
  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:];
>>> 
>>> - 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/mabdullah%40karelia.com
>> 
>> This email sent to mabdul...@karelia.com
> 

___

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


Re: Invalidating UIImageView's image cache

2020-09-23 Thread Mike Abdullah via Cocoa-dev
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  
> 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  wrote:
>> 
>> 
>>> On Sep 22, 2020, at 1:46 PM, Eric Lee via Cocoa-dev 
>>>  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 
>>>  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:];
>> 
>> - 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/mabdullah%40karelia.com
> 
> This email sent to mabdul...@karelia.com

___

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


Re: Invalidating UIImageView's image cache

2020-09-22 Thread Alex Zavatone via Cocoa-dev
It’s probably getting the same image from within the bundle based on the path.  

> On Sep 22, 2020, at 8:12 PM, Eric Lee via Cocoa-dev 
>  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  wrote:
>> 
>> 
>>> On Sep 22, 2020, at 1:46 PM, Eric Lee via Cocoa-dev 
>>>  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 
>>>  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:];
>> 
>> - 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/zav%40mac.com
> 
> This email sent to z...@mac.com

___

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


Re: Invalidating UIImageView's image cache

2020-09-22 Thread Eric Lee via Cocoa-dev
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  wrote:
> 
> 
>> On Sep 22, 2020, at 1:46 PM, Eric Lee via Cocoa-dev 
>>  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 
>>  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:];
> 
> - 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


Re: Invalidating UIImageView's image cache

2020-09-22 Thread Carl Hoefs via Cocoa-dev


> On Sep 22, 2020, at 1:46 PM, Eric Lee via Cocoa-dev 
>  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 
>  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:];

- 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


Re: Invalidating UIImageView's image cache

2020-09-22 Thread Eric Lee via Cocoa-dev


> 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 
 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? 
___

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


Re: Invalidating UIImageView's image cache

2020-09-21 Thread Uli Kusterer via Cocoa-dev
On 2. Sep 2020, at 02:40, Carl Hoefs via Cocoa-dev  
wrote:
> I've tried setting UIImageView.image=nil, UIImageView.animationImages=nil, 
> toggling UIImageView.hidden, wiping the sandbox, etc., but no joy. Of course, 
> restarting the app does force-flush the cache, but that's a no-go.
> 
> The only way I've found to invalidate UIImageView's caching (without killing 
> the app) is to play games like generating unique filenames for each run of 
> the processing loop of the app. Apparently UIImageView tracks _filenames_ to 
> determine when to flush/update its cache!
> 
> So, if there actually exists a kosher way to do this, I welcome any/all hints!

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?

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de

___

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


Invalidating UIImageView's image cache

2020-09-01 Thread Carl Hoefs via Cocoa-dev
Q: What is the proper way to invalidate UIImageView's image cache?

- - -

I have an iPad app that generates a series of medical analysis UIImages in the 
~/Documents area of the sandbox. I then display those images in an automated 
sequence on the GUI.

Each time the app runs through its processing loop, it generates a new set of 
analysis images _of the same filename_ in the ~/Documents area of the sandbox, 
effectively overwriting the previous set of files there. 

To display (sequence through) the generated images, I feed them to UIImageView 
with 
imageView.image = [UIImage animatedImageWithImages::]...
or 
imageView.animationImages = [NSArray ]...

So far, so good; they display nicely. But, once an initial set of images has 
been fed to UIImageView, it will _not_ update the images displayed with a new 
set (because they have the same filenames); instead UIImageView displays the 
originally cached set, even though that version of the file set no longer 
exists in the sandbox.

I've tried setting UIImageView.image=nil, UIImageView.animationImages=nil, 
toggling UIImageView.hidden, wiping the sandbox, etc., but no joy. Of course, 
restarting the app does force-flush the cache, but that's a no-go.

The only way I've found to invalidate UIImageView's caching (without killing 
the app) is to play games like generating unique filenames for each run of the 
processing loop of the app. Apparently UIImageView tracks _filenames_ to 
determine when to flush/update its cache!

So, if there actually exists a kosher way to do this, I welcome any/all hints!

-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