Re: Unjustified CPU load with a simple Document .app
Re: Unjustified CPU load with a simple Document .app
- Subject: Re: Unjustified CPU load with a simple Document .app
- From: ettore <email@hidden>
- Date: Sat, 07 Jun 2003 20:07:45 -0700
On 2003-06-06 21:26:07 -0700 Daniel Zitter <email@hidden> wrote:
From: ettore <email@hidden>
To: email@hidden
when the timer ends. My project is composed by the MyDocument class, its Nib and the MainMenu.nib which is untouched. The GUI has
- 2 TextFields: "minutes to wait" and the "message" to be displayed.
- 2 buttons: "Start" and "Invalidate": "Start" creates the NSTimer and "Invalidate" calls the `invalidate:' method of NSTimer.
Everything works except for one fact: when a document is open, and SimpleTimer is the active application (i.e. its menus are visible on the menubar at the top of the screen) I notice - with `top' from the terminal - a big CPU load (20%-30%) related to SimpleTimer, even when the NSTimer object is not allocated and the mouse is not moving. If I close all the documents (not the app), or either click on some other application, the SimpleTimer load drops to 0.
Any chance the code you've posted differs from the code which loaded the CPU?
(Since you don't explicitly invalidate the timer other than in invalidateTimer:, you might be collecting a number of firing timers if the timers are repeating or the enable/disable button code wasn't working right. The code posted doesn't seem to do that, but I don't want to assume.)
In general I think it's a good habit to invalidate a timer (even non-repeating) when you are done with it, which is usually in the action invoked by the timer. That way, even if there is a retain/release/autorelease bug in your code, you don't end up with a drastically worse situation: inconceivable sporadic behavior.
[snip]
Thanks for the help. Anyway it was not a NSTimer problem, since I had the load even before instantiating the timer. Strangely, I found out that once the NSTimer was started, the load was going away to ~0%. The fact is my document had a "Return" key equivalent setting associated with the "Start" button, so that I just had to press return to start the timer ("Start" was a flashing button). Taking the equiv. setting out in IB removed the load. Then I noticed that this 20% - 30% load happens with all applications who have a document with a "flashing" button, when they are the active application and that document is the active document !
(An easy way to see this is for example trying to close an unsaved doc in TextEdit (or whatever), so that the saving sheet remainder drops down.)
I don't know if this normal, yet it's something I never noticed before. Any explanations? Now I understand why sometimes I was experiencing some increased "random" delays in my OS X user experience.
Anyway, it does not cause _a lot_ of problems because the load stays only if the document with a flashing button is selected: if you click on another app or select another document the load goes away.
Ettore
_______________________________________________
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.