> On Jun 7, 2020, at 3:27 AM, Gabriel Zachmann via Cocoa-dev 
> <cocoa-dev@lists.apple.com> wrote:
> 
> For large images, this "thumbnail" can well occupy 1 GB of RAM.

That seems excessive. Shouldn’t you shrink it down to the actual screen 
resolution first?

> My current approach is to calculate the amount of unused memory,
> whenever a new images is put in the cache, and if that is below 1.5 GB, I 
> reduce the size of the cache

Memory is a complicated thing in a modern OS. Memory as address space and 
memory as RAM have little to do with each other. Trying to estimate how much 
memory is free for you to use is fairly pointless unless you want to learn a 
lot about the kernel and VM.

Usually the best compromise is to allocate purgeable address space and use that 
for your caches. The kernel can then toss out that memory and reuse it for 
something else if space runs low. There are low-level C APIs for this, and I 
think some Cocoa ones too,,but it’s been a decade since I’ve used them so I 
don’t recall the details...

—Jens
_______________________________________________

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