Re: Relieving memory pressure
Re: Relieving memory pressure
- Subject: Re: Relieving memory pressure
- From: Alex Zavatone via Cocoa-dev <email@hidden>
- Date: Mon, 8 Jun 2020 14:40:23 -0500
> On Jun 7, 2020, at 3:15 PM, Steve Christensen via Cocoa-dev
> <email@hidden> wrote:
>
> For slide shows that I’ve seen, they typically display each image for several
> seconds at a time. If that’s the case, why can’t you just load the next image
> from disk on a background queue while the current image is being displayed
> and not have to worry about memory usage needed to cache multiple images? (I
> am assuming that you’ll need to load each image once anyway.)
Yeah, that’s like the preloading I suggested on an earlier thread about loading
screensaver images. Then after an image has transitioned out of display, you
can nil all references to it. If you know the order of when images will be
displayed and removed, you can even create a mechanism for loading what’s to
come and removing what has disappeared. Pre-calculate your display array,
unload everything you don’t need anymore and preload everything that will be
displayed next. Just make sure you don’t unload anything that is used in the
current or next display.
You’d have a previous list of images, a current list of images and a next list
of images.
Just do some set operations to make sure you’re not unloading and loading the
same image.
For unloading, I’m referring to making the image reference count 0 and then
nilling variables.
So, you’d have this mechanism rolling along on a thread while you have another
process for the display of the images.
How does that sound?
> If caching is required—apologies if I missed the “why” in earlier
> comments—then have you looked at NSCache? From the docs:
>
> The NSCache class incorporates various auto-eviction policies, which ensure
> that a cache doesn’t use too much of the system’s memory. If memory is needed
> by other applications, these policies remove some items from the cache,
> minimizing its memory footprint.
>
>
>> On Jun 7, 2020, at 5:31 AM, Gabriel Zachmann via Cocoa-dev
>> <email@hidden> wrote:
>>
>> Good question.
>>
>> Well, some users want to feed my app with image files of 100 MB, even up to
>> 400 MB (mostly jpeg compressed).
>> Those images have resolutions of over 8k, sometimes over 10k.
>>
>> The slideshow app needs to be able to zoom into those images with at least a
>> factor 2x scaling.
>>
>> So I figured that if someone has a 4k monitor, creating thumbnails with 8k
>> resolution maximum should be sufficient.
>>
>> An 8k x 8k image needs at least 200 MB (1 byte per channel).
>> I don't know how CGImage stores the uncompressed images internally,
>> but my experience seems to indicate that it uses significantly more memory
>> than that.
>> (maybe it uses two bytes per channel, or even floats, or there is some other
>> aux data)
>>
>>> What do you need a 1GB thumbnail for? There is no screen that can display
>>> that. For a slideshow app you could scale your thumbnails at creation time
>>> to the users biggest screen pixel size, don’t you think?
>>>
>>> Christos Konidaris
>
> _______________________________________________
>
> 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