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

  • SEARCH
  • Home
  • 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 556139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:53:18+00:00 2026-05-13T11:53:18+00:00

I am trying to run a timer in the background of my application, i

  • 0

I am trying to run a timer in the background of my application, i am using the timer heavily in my application and i’d rather running it in the background, However i am getting memory leaks when trying to release the NSAoutreleasePool. My Timer class is singleton, so if i start new timer the old timer get dealloc it .

+ (void)timerThread{

    timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerThread) object:nil]; //Create a new thread
    [timerThread start]; //start the thread
}

//the thread starts by sending this message
+ (void) startTimerThread
{
    timerNSPool = [[NSAutoreleasePool alloc] init];
    NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(startTime:) userInfo:nil repeats:YES];
    //timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(startTime:) userInfo:nil repeats:YES];
    //[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    [runLoop run];
    [timerNSPool release];
}

+ (void)startTime:(NSTimer *)theTimer{

    if(timeDuration > 1)
        timeLabel.text = [NSString stringWithFormat:@"%d",--timeDuration];
    else{
        [self stopTimer];
        [delegate timeIsUp];
    }

}
+ (void) stopTimer{

    if(timer != nil)
    {       
        [timerThread release]; 
        [timeLabel release];
        [timer invalidate];
        timer = nil;
    }

}

I never had a problem running the NSTimer on the main thread runLoop with application autoreleasepool.
I am getting leak at [timerNSPool release];
GeneralBlock-16 Malloc WebCore WKSetCurrentGraphicsContext

What causing the Leak is updating UI from a secondary thread :

timeLabel.text = [NSString stringWithFormat:@"%d",--timeDuration];

However i added another method updateTextLbl, then i am calling it using this

[self performSelectorOnMainThread:@selector(updateTextLbl) withObject:nil waitUntilDone:YES];

on the main thread. I did not have leaks at all , but this will defeats the purpose of having a second threads.

This my first post , and i appreciate any help Thanks… in advance….

  • 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-13T11:53:18+00:00Added an answer on May 13, 2026 at 11:53 am

    You’re updating your UI in +startTime:, but that method does not run in the main thread. That may be the source of the WebCore warning you’re seeing.

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

Sidebar

Related Questions

Im trying to make a countdown timer run in the background of my activity,
Background: I'm getting a mapping failure when trying to use nHibernate. The application consists
I am trying to get a timer run every minute in sync with the
I'm trying to use a timer in C# to run a method at an
I'm trying to use C# to control a command line application background, which can
I'm trying to start an activity from a service running in background but its
I wish to run a long-running script in the background upon receiving a request.
I'm trying to build a simple web application using Node.js and CouchDb. The application
I am trying to run a task in the background checking a database for
I'm trying create a simple background periodic task using Django-Celery-RabbitMQ combination. I installed Django

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.