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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:40:35+00:00 2026-05-24T04:40:35+00:00

In that piece of code, I have both NSLog that says dict has a

  • 0

In that piece of code, I have both NSLog that says dict has a retain count of 1.
As the timer can be triggered in a long time if there are many objects into the array, May I retain dict given into user info ? Because I guess it’s autorelease, and the scheduledTimerWithTimeInterval does not seems to retain it.

Theoricaly ?
Practically ?

- (void) doItWithDelay
{
    NSArray* jobToDo = /* get an autorelease array */

    NSTimeInterval nextLaunch = 0.1;
    int i=1;

    for (NSDictionary* dict in jobToDo) {
        NSLog(@"dict %d has %d retain count", i++, [dict retainCount]);

        // HERE [dict retain] ???
        [NSTimer scheduledTimerWithTimeInterval:nextLaunch target:self selector:@selector(doIt:) userInfo:dict repeats:NO];   
        nextLaunch += 1.0;
    }
}

- (void) doIt:(NSTimer*)theTimer 
{    
    NSDictionary* dict = [theTimer userInfo];

    NSLog(@"dict has now %d retain count", [dict retainCount]);

    // Do some stuff with dict
}
  • 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-24T04:40:36+00:00Added an answer on May 24, 2026 at 4:40 am

    Apple NSTimer document say that it will retain the userInfo. Below is quoted from the document…

    The object you specify is retained by the timer and released when the timer is invalidated.

    Your second NSLog say 1, so i guess it already been autoreleased but the timer still retain it.

    EDIT: As bbum suggested, we should not rely on retain count. So we’re lucky that the doc state it clearly.

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

Sidebar

Related Questions

I have a piece of code (below) that can get the text of an
I have a piece of code that needs to handle both JSONObject and JSONArray
I have a code piece that I am reviewing (using FindBugs ). public class
Here is the piece of code that I have used for Java 5.0 TreeSet<Integer>
Assume that I have this piece of code: @interface Foo : NSObject { Bar
I have the following piece of code that takes in some words, stores them
I have a piece of code that was written by someone else before the
I have the following piece of code that generate a jquerymobile-style button <a href=#
I have the following piece of code that finds all elements in the document
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();

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.