Re: Performance
Re: Performance
- Subject: Re: Performance
- From: Matt Neuburg <email@hidden>
- Date: Mon, 16 Nov 2009 08:54:15 -0800
- Thread-topic: Performance
On Sun, 15 Nov 2009 22:14:32 -0800 (PST), Chris Carson <email@hidden>
said:
>The application runs pretty well, and running it through the Leaks instrument
there are no leaks except for 16-bytes when the application is first starting
caused by IOUSBLib. However, looking at it in the Activity Monitor, the real
memory used starts off at 25 MB and steadily grows to 250+ MB while the virtual
memory starts off at about the same and steadily grows to about the same or
sometimes close to 500MB, over the course of several minutes. This especially
happens if I don't move the mouse for a while, or don't have the application in
focus. As soon as a move the mouse or bring the application into focus, it's as
if an autorelease pool is drained and the memory drops back down to 30-40MB real
and 30-40MB virtual. This is annoying since the application hangs for 5 seconds
or so when this memory draining is occurring. Has anyone dealt with this before?
Any ideas on what could be causing this and how to work around it?
You have already understood it. :) If you autorelease stuff (or ask the
framework to make you an autoreleased object), you are saying: Release this
when you feel like it. "When you feel like it" doesn't happen when the app
isn't getting any events in the background.
The solution is either Don't Do That (i.e. if these are objects that you
own, then release them, don't autorelease them) or (more likely) introduce
your own autorelease pool into your loop, releasing it at the bottom of the
loop or (even more likely) at the bottom of every n loops, where n is some
convenient integer.
This point is nicely covered (though rather densely, and without an example)
here:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Memory
Mgmt/Articles/mmAutoreleasePools.html
"If you write a loop that creates many temporary objects, you may create an
autorelease pool inside the loop to dispose of those objects before the next
iteration. This can help reduce the maximum memory footprint of the
application."
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
_______________________________________________
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