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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:55:46+00:00 2026-05-17T00:55:46+00:00

Scenario 1: For a UIViewController, is it better to (1) create an ivar for

  • 0

Scenario 1:
For a UIViewController, is it better to (1) create an ivar for a UIView that I access again in 1 or 2 functions outside of loadView? Or, (2) should I just tag it in loadView and then use - (UIView *)viewWithTag:(NSInteger)tag to access it again in the other functions? I’m guessing that option 1 increases the memory by the size of a pointer, so 32/64-bits, and creates accessor methods (assuming I declare @property & @synthesize), and then requires releasing the ivar in dealloc and setting it to nil in viewDidUnload… and that option 2 saves memory, has less setup code, but costs some processing time and a little extra code to find the view by its tag. Am I right about all this?

In this scenario, it feels best to use an ivar, but I’m not sure.

Scenario 2:
What about for a custom subclass of UIView that has 5 subviews? Bearing in mind that I’ll have about 30 instances of this custom subclass in memory at a given time (They’ll be subviews of tableViewCells.), should I use 5 ivars for the subviews, or should I tag them all?

In this scenario, I’m thinking the memory saved by tagging them all would be worth the small performance hit of searching for them with - (UIView *)viewWithTag:(NSInteger)tag.

Thoughts?

Thanks!

Matt

  • 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-17T00:55:46+00:00Added an answer on May 17, 2026 at 12:55 am

    Considering that difference in memory usage is negligible (unless you’re going to have 100 of these views, in which case you might want to look into how you can reuse some of those views), you should probably consider what would make your code more readable and maintainable. I personally think that using an ivar would be more readable, but it’s also possible that for your particular case using tags would be more readable.

    When writing code, I always try to think about the person who’s going to reading the code a year or two years from now. That person might be me, or it might be someone else, but either way, I know that person will appreciate readable code. They’re less likely to thank me for saving 1k of memory on a device that has at least 128 MB of RAM.

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

Sidebar

Related Questions

Scenario: You have an ASP.Net webpage that should display the next image in a
Scenario is that we send out thousands of emails through SMTP server. Content is
Scenario: An event is raised in class A that needs to be handled by
Scenario: A stored procedure receives from code a DateTime with, let's say DateTime.Now value,
Scenario: Attempting to import many (>100), large(>1M recs) flat-files (csv). Problem: Many records are
Scenario: I'm currently writing a layer to abstract 3 similar webservices into one useable
Scenario I have two wrappers around Microsoft Office, one for 2003 and one for
Scenario: Let's say I have four very similar applications (i.e. most of the functionality
Scenario You've got several bug reports all showing the same problem. They're all cryptic
Scenario: Let's say I have two tables, TableA and TableB. TableB's primary key is

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.