Re: Relieving memory pressure
Re: Relieving memory pressure
- Subject: Re: Relieving memory pressure
- From: Jens Alfke via Cocoa-dev <email@hidden>
- Date: Sun, 7 Jun 2020 22:03:54 -0700
> On Jun 7, 2020, at 3:27 AM, Gabriel Zachmann via Cocoa-dev
> <email@hidden> 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 (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