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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:03:23+00:00 2026-05-23T00:03:23+00:00

For example, the NSString * defaultCellIndentifier = @HelloWorld; When should I deallocate that? Are

  • 0

For example, the NSString * defaultCellIndentifier = @”HelloWorld”;

When should I deallocate that? Are string the only variable in objective-c that can be static?

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [BNUtilitiesQuick UtilitiesQuick].currentBusiness=[[BNUtilitiesQuick getBizs] objectAtIndex:[indexPath row]];
        //Business * theBiz=[[BNUtilitiesQuick getBizs] objectAtIndex:[indexPath row]];
        static NSString * defaultCellIndentifier = @"HelloWorld";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier: defaultCellIndentifier];
        //UITableViewCell*cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Hello"] autorelease];;
      ...



        return cell;
    }
  • 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-23T00:03:23+00:00Added an answer on May 23, 2026 at 12:03 am

    In this case you can’t really deallocate the object, as it is a static string which lives in the read-only section of your program that is mapped into memory. Doing [@"foo" release] has no effect. You could only assign nil to your variable, but that doesn’t make the string go away.

    In general, the point of a static variable is to stick around so you don’t want to deallocate it. As long as it’s not a mutable array that only grows and takes up huge portions of memory this isn’t a problem.

    Edit to clarify:

    Usually, you use a static variable to allocate something that is supposed to be more or less static once. A static variable is shared with all instances, so if you change it, all instances of your class will see this change. Especially with multiple threads this can be a problem, but it’s usually safe to do this:

    - (void)foo
    {
        // It's important to initialize this to nil. This initialization
        // is only done ONCE on application start ! It will NOT overwrite
        // any values you've set later on.
        static NSDate *someImportantDate = nil;
    
        if (!someImportantDate) {
            // Allocate the static object. We will only get here once.
            // You need to make sure that the object here is not autoreleased !
            someImportantDate = [[NSDate alloc] init];
            // or:
            someImportantDate = [[NSDate date] retain];
        }
    
        // Do stuff.
    }
    

    But once created, you shouldn’t touch the static variable again. If you find the need to change it, you should use an instance variable on your class instead of using a static variable.

    Also a warning about multithreading: if you have multiple threads you should make sure that the initalazition of the static variable is done before multiple threads might access it. Because if two threads would each see the uninitialized (nil) variable they would both try to set the new value (race condition) which in theory could even lead to crash. Once the variable is initialized and you only read the variable (and it’s not a mutable object) it’s safe to access the value from different threads.

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

Sidebar

Related Questions

I want to pass a variable to a UIButton action, for example NSString *string=@one;
I have the following example class: Test.h: @interface Test : UIButton { NSString *value;
Example: You have a shortcut s to SomeProgram in the current directory. In cmd.exe
Example I have Person , SpecialPerson , and User . Person and SpecialPerson are
Example: select ename from emp where hiredate = todate('01/05/81','dd/mm/yy') and select ename from emp
example: a_list = [1, 2, 3] a_list.len() # doesn't work len(a_list) # works Python
example: I want to see if array[5] holds a value or is empty.
Example C API signature: void Func(unsigned char* bytes); In C, when I want to
Example: an Order object (aggregate root) has a collection of OrderLine objects (child entities).
Example: The user login to the webpage => Click on a button This action

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.