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 4627076
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:30:52+00:00 2026-05-22T03:30:52+00:00

I am using an NSTimer in my view class that is called every 15

  • 0

I am using an NSTimer in my view class that is called every 15 seconds. My problem is, it is working properly, but my app is getting slow, because it is showing its performance to the whole app. So I want to pause the NSTimer when my view disappears from its superview and restart the timer when it appears. Please help me in solving the problem. Here is my code:

- (void) viewWillAppear:(BOOL)animated
{

    if(!Thread_bool)
    {
        //[spinner startAnimating];
        NSTimer *timer_new1=[[NSTimer alloc] init];
        timer_new1=[NSTimer scheduledTimerWithTimeInterval:2.0 target:self                selector:@selector(threadMethod) userInfo:nil repeats:YES];
        self.timer_new=timer_new1;
        [timer_new1 release];
        [self.tableView setEditing:NO];
        isEditing=NO;
        Thread_bool=YES;    
    }
}

-(void)viewWillDisappear:(BOOL)animated
{
    [self.timer_new invalidate];
    timer_new=nil;  
}
  • 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-22T03:30:52+00:00Added an answer on May 22, 2026 at 3:30 am
    NSTimer *timer_new1=[[NSTimer alloc] init];
    timer_new1=[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(threadMethod) userInfo:nil repeats:YES];
    self.timer_new=timer_new1;
    [timer_new1 release];
    

    In first line you have alloced a timer and in second line another timer is created and assigned to timer_new1. So you lost the reference to the timer that was alloced in previous line and that is leaked. You don’t need the first line alloc. Do this:

    NSTimer *timer_new1 = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(threadMethod) userInfo:nil repeats:YES];
    

    And remove [timer_new1 release]; (I am assuming that self.timer_new is retained). Also in viewWillDisappear do self.timer_new = nil; instead of timer_new=nil;. Adding that self will call the setter and correctly release the previous timer.

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

Sidebar

Related Questions

Using C#, I need a class called User that has a username, password, active
I'm using an NSTimer to do some rendering in an OpenGL based iPhone app.
I'm working on an iPad app, it has a few videos within views using
I am porting an app that I originally wrote using the accelerometer for IOS
I want to add a array of UIImages to UIImageView using NSTimer. Such that
I have a NSTimer that fires with an interval of 3 seconds to decrease
I recently switched from using NSTimer to CVDisplayLink to redraw my OpenGL animation, but
I am using [NSTimer scheduledTimerWithInterval:selector:@selector(loop):repeats:YES] to create a neverending loop with -loop() being called
I am currently using NSTimer to load a Please Wait alert view in my
I'm calling setNeedsDisplayInRect from an NSTimer function every two seconds. This works perfectly, and

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.