Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTimer memory problem

NSTimer memory problem
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Murray, Utah, USA
Status: Offline
Reply With Quote
May 4, 2001, 09:09 AM
 
Okay, in the documentation that came with PB, it states that an NSTimer will add itself to the RunAppLoop function and stay there forever. No matter what, you can't get rid of it; the best you can do is "invalidate" the timer.

I find this very disconcerting. I'm not programming this example program that I'll use here, but still, for future reference I'd like to have other possible options....

Let's say we're writing an Othello game. Every turn made, you want to animate the discs being flipped, so you use a timer to animate them at a good speed. Now when they are done flipping you "invalidate" the timer, but the object still lingers around! I could delete it i guess, but it is still in the RunLoop!?

Now when the next player moves, we need to flip discs again. So, now that the other timer is invalidated, we make a new timer ... until there are 'n' timers floating around, all invalidated....

So, a couple questions:

1. Can you reactivate a timer once you've deactivated it (perhaps by "firing" it)?

2. How does the RunLoop work? If whenever it adds a timer it adds a (for simplicity sake) for(all timers) { if ([timer[i] isValid]) { ... } } then I DON'T want these timers floating around when I'm done with them... can I get rid of them?

Thanks!
Jeff
     
Junior Member
Join Date: Mar 2001
Status: Offline
Reply With Quote
May 5, 2001, 10:48 AM
 
Originally posted by jmassung:
(...)

So, a couple questions:

1. Can you reactivate a timer once you've deactivated it (perhaps by "firing" it)?
You can reinsert the timer into the run loop using NSRunLoop's addTimer:forMode: method. Let us know if this works!



2. How does the RunLoop work? If whenever it adds a timer it adds a (for simplicity sake) for(all timers) { if ([timer[i] isValid]) { ... } } then I DON'T want these timers floating around when I'm done with them... can I get rid of them?

Thanks!
Jeff
I doubt it. I can't imagine that the run loop would keep input sources around whose limit dates are past, and the Carbon Event Manager (which uses the same mechanism as NSRunLoop) supports the contention that timers are removed. Don't worry about it.

-Peter

[This message has been edited by Wixar (edited 05-05-2001).]
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:56 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2