Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:33:29+00:00 2026-05-23T23:33:29+00:00

Sometimes I get confused about when not releasing an object. I have: NSTimer *timer2;

  • 0

Sometimes I get confused about when not releasing an object. I have:

NSTimer *timer2;

timer2 = [NSTimer scheduledTimerWithTimeInterval: (5)
                                         target: self
                                       selector: @selector(someMethod:)
                                       userInfo: nil
                                        repeats: YES];

and the method that get’s executed every five seconds is:

-(void) someMethod:(NSTimer*)theTimer
{
   NSLog(@"code got executed");
}

I have another method that places another nib file on my root view controller:

ViewControllerObjetivos *control = [ViewControllerObjetivos alloc];

[control initWithNibName:@"ViewControllerObjetivos" bundle:nil];

UINavigationController *navControl = [[UINavigationController alloc]
                                      initWithRootViewController:control];

[self presentModalViewController:navControl animated:NO]; 
[navControl setNavigationBarHidden:YES];

[control release];
[navControl release];

when I call that last method a new nib file get’s placed on the root view controller. And someMethod still gets called!

so I am confused if I should release the timer2 because I did not use the word init or alloc nor copy to initialize it. So what am I suppose to do? should I just stop it then call the last method that I showed? or maybe should I release the whole nib file since I am going to be working with a new one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:33:30+00:00Added an answer on May 23, 2026 at 11:33 pm

    The correct way to stop a timer is calling its invalidate method.

    invalidate

    Stops the receiver from ever firing again and requests its removal from its run loop.

    In your case, you could store timer2 in an ivar of your class and then send it invalidate at the proper moment, i.e., when you display the second nib (if I am not wrong). Not doing so will leave the timer running forever, as you witnessed.

    If you set repeats to NO, the timer will be automatically invalidating after firing the first time:

    repeats

    If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using MVP for a while .Sometimes I get confused what actions
I'm confused about which way is the best to have multiple tables get synced
When running my application I sometimes get an error about too many files open
We have some applications that sometimes get into a bad state, but only in
Sometimes I get a broken background in Chrome. I do not get this error
I have the following code running, but I sometimes get some sort of concurrency
RegEx has always confused me. I have a string like this: IDE\DiskDJ205GA20_____________________________A3VS____\5&1003ca0&0&0.0.0 Or Sometimes
im pretty confused about lambdas and actually im not even sure i need them
Huh, looking at all those string functions, sometimes I get confused. One is using
I use GridViews pretty often and sometimes I get confused to where to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.