Re: Forcing garbage collection, freeing up memory, thrashing
Re: Forcing garbage collection, freeing up memory, thrashing
- Subject: Re: Forcing garbage collection, freeing up memory, thrashing
- From: "Sean McBride" <email@hidden>
- Date: Tue, 4 Nov 2008 18:51:23 -0500
- Organization: Rogue Research
On 11/4/08 11:21 AM, Bill Bumgarner said:
>Have you used the Object Graph instrument in Instruments and/or gdb's
>info gc-references/gc-roots to determine what is sticking around and
>why? Analysis with said tools can tell you exactly what is going on.
>
>In this case, though, I have an idea what is happening. I bet your
>image objects are being falsely rooted -- being kept alive -- by the
>stack. The collector must scan the entire stack for pointers,
>including a bit of slop beyond the "bottom" of the stack (because the
>bottom may not be the bottom). That is, GCC's convention is that the
>stack layout is opaque.
>
>Thus, it is possible for objects to live for longer than they should
>if there is a pointer (or something that looks like a pointer) on the
>stack somewhere... anywhere... that refers to the object.
>
>Easy fix; clear the stack at the top or bottom of your loop. Clear
>it from one function above any that stick references on the stack.
>I.e. make your loop a simple wrapper around a function where the loop
>clears the stack at the top or bottom.
>
>The collector provides API for this:
>
> objc_clear_stack(OBJC_CLEAR_RESIDENT_STACK);
>
>NSRunLoop does this automatically as it passes through each loop.
>Since you are blocking the run loop, you'll have to do this for it.
Thanks very much for your reply Bill.
I'm afraid one of us is misunderstanding the other though. My object is
being collected when I expect. And by 'being collected' I mean the
object's finalize was called when I expect (no later than after
objc_collect()). 'info gc-references/gc-roots' confirms this.
What is not happening is my "Real Memory" usage according to Activity
Monitor going down correspondingly. It starts at say 200 MB. Then I do
my big loop (load big images, downsample them, force collection, big
images finalize, repeat). During this loop it goes up to ~7 GB. As I
have only 5 GiB of RAM I start to thrash horribly. Shortly after my
loop is done, my "Real Memory" usage goes to 400 MB or so, which is
where I expect it. I suspect servicing the runloop is what brings it
down, but I don't know.
I tried objc_clear_stack() but it changes nothing. I'll take a look at
Instruments, though I haven't had much luck with it in the past, since
it's a 32bit app, it runs out of memory pretty fast and crashes. :)
Any other thoughts?
Thanks,
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
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