Re: memory management question
Re: memory management question
- Subject: Re: memory management question
- From: matt neuburg <email@hidden>
- Date: Sat, 20 Mar 2004 08:05:06 -0800
On Fri, 19 Mar 2004 14:21:29 -0800, Shawn Erickson <email@hidden>
said:
>
On Mar 18, 2004, at 3:36 PM, matt neuburg wrote:
>
>
> My app reads lots of TIFFs from disk. As it does this, I
>
> can see (with MemoryStick) that the amount of the
>
> computer's "inactive" memory goes way up - that is, more
>
> and more RAM is being allocated to "inactive" memory,
>
> until RAM fills up (the amount of "free" memory drops to
>
> near zero). When the app is done, this memory is not
>
> given back.
>
>
This is normal, it is the UBC (universal buffer cache)
>
attempting to cache data that may possibly be used again
>
in an attempt to avoid disk or network I/O.
>
>
>
> What I'd like to do is give back the memory after I'm
>
> done with each file. I have tried all the Cocoa tricks I
>
> can think of (autorelease pools everywhere, explicit
>
> init and release wherever possible, and so forth) but
>
> nothing helps.
>
>
You really don't need to give it "back" because it isn't
>
really taken. The UBC is simply using available pages in
>
physical RAM to hold onto information. If someone needs a
>
page and a free one isn't available then an inactive one
>
will get used (since it is caching file data no page out
>
is needed, it just zeros it and returns the page like it
>
would if it was a free page).
That is a lovely theory, and perhaps some varieties of Unix work that way,
but on Mac OS X that is not in fact what happens. What happens is that the
"inactive" stuff in memory accumulates and overwhelms physical RAM and
pageouts start to happen, and swapfiles are created. On my machine, a single
run of my program, reading, say, a dozen large TIFFs, can easily cause two
additional swapfiles to be created. This is *not* due to a leak in my
program! The amount of "wired" and "active" RAM in use does not increase.
This is all due to "inactive" RAM swelling. The mere act of reading large
TIFFs from disk seems to cause the problem.
The problem is alleviated somewhat if the user happens to have extremely
large amounts of RAM, but that is not really acceptable. The user really
should not need more RAM to run my program than is necessary to hold in
memory two images: the TIFF currently being read, and the image I am
creating (I'm making a thumbnail of each successive TIFF and "pasting" the
thumbnail into my image).
Once a TIFF has been read from disk, it will not be read again. The system
is wrong to cache it; this is a false optimization. Thus, I am looking for a
way to get the system to "give back" the RAM occupied by each TIFF after I
am done with it. m.
--
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide! NOW SHIPPING...! (Finally.)
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.