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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:54:38+00:00 2026-05-23T16:54:38+00:00

I have a pretty simple question. In the following piece of code, is it

  • 0

I have a pretty simple question. In the following piece of code, is it better to place the activity indicator in the dealloc since I am starting and stopping the activity indicator after it is added to subview?

- (void)viewDidLoad {
    [super viewDidLoad];
    // add activity indicator
    activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityIndicator.center = CGPointMake(self.view.bounds.size.width / 2.0f, self.view.bounds.size.height / 2.0f);

    activityIndicator.hidesWhenStopped = YES;
    [self.view addSubview:activityIndicator];
    [activityIndicator release];      // SHOULD THIS BE PLACED IN DEALLOC?

    [self loadFax];
}
  • 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-23T16:54:39+00:00Added an answer on May 23, 2026 at 4:54 pm

    Actually, I would place the release in viewDidUnload, besides dealloc.

    Not doing so could result in a memory leak in case your app receives a memory warning and all of it’s views are released; indeed, in this case the view would be loaded once again when needed and this would cause a second allocation for you activity indicator, without the previous instance being released.

    Keep in mind, as per comment below, that releasing in viewDidUnload does not mean you may skip releasing in dealloc. This for two reasons: if you are running iOS
    2.x there is no viewDidUnload; furthermore, when your view controller is released normally, viewDidUnload will not be called. So the suggestion is doing in both places and do not forget to set the ivar value to nil after doing it.

    In this case, it would be better to release as you are doing, but then at least set the ivar value to nil, otherwise you could think you own the object still.

    If you used a retain property and made the assignment like this:

      Self.activityIndicator = ....
    

    This would not be the case, still I think that releasing in viewDidUnload what you created in viewDidLoad is better practice in general.

    Here what the docs about viewDidUnload.

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

Sidebar

Related Questions

This is a pretty simple question.. lets say I have the following. wordArray WORD
i have pretty simple simple question (i hope so). How do i change the
I have a pretty simple question which perhaps someone familiar with Server/Client design &
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
Pretty simple question. I'm quite certain I have the Class, method, codebehind, etc linked
hopefully a pretty simple question this time. I have a Select method in a
I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
I have a pretty simple question, but for some reason I am drawing a
I have a probably pretty simple question but I am still not sure! Actually
This seems like a pretty simple question, but I have not managed to find

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.