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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:54:15+00:00 2026-06-01T22:54:15+00:00

If I create a property of type NSString without allocating space to it and

  • 0

If I create a property of type NSString without allocating space to it and assign some value to it , it works. Where as I do the same thing for a UITextField it doesn’t..? I am creating a textfield programmatically…. any help is appreciated.

EDIT:

I have created two properties in .h of SecondViewController…

@property (nonatomic,retain) NSString *text;
@property (nonatomic, retain) UITextField *textField;

Now if I create a new object secondViewController and say do this…

   secondViewController.text=@"Second View Controller";

this value is retained even though I did not alloc Memory to it…

and if i try to do the same thing for a textfield object this does not happen unless I allocate memory to it..

here is my SecondViewController…

//
//  SecondViewController.m
//  Tester
//
//  Created by Ankit on 4/16/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "SecondViewController.h"

@implementation SecondViewController
@synthesize  text,textField;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"The text is %@",text);

//   textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)]; (if I `uncomment this than only this textField is visible)`
    textField.frame=CGRectMake(10, 200, 300, 40);
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.font = [UIFont systemFontOfSize:15];
    textField.placeholder = @"enter text";
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyDone;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
    [self.view addSubview:textField];

//    textfield=[[UITextField alloc] init];
//    textfield.frame=CGRectMake(10,10,60, 30);
//    [self.view addSubview:textfield];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.text=nil;
    self.textField=nil;
    NSLog(@"viewDidUnLoad");
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
-(void)dealloc{
    NSLog(@"dealloc");
    [text release];
    [textField release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
  • 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-06-01T22:54:16+00:00Added an answer on June 1, 2026 at 10:54 pm

    A property is just a reference to an object and the ‘space’ has to come from somewhere else. The only real difference with NSString is that the space is often in the form of a literal so you don’t see the allocation directly. @”Hello” is a real object that you can reference but in other cases you use [[NSString alloc] init…] constructions that are the same as [[UITextField alloc] init…] constructions.

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

Sidebar

Related Questions

The EF will create Nvarchar data type from a property of type String .
I want to create an attached property of type ObservableCollection<Notification> and bind it to
This is a bug? Using NHibernate.Expression.Example.Create(userExample) if my class use Int32 on property 'Type'
I have a user control and I want to create a property of type
I want to create a property grid (the one which is similar to the
Is there any way to create a property like this C# property in Objective-C?
I am trying to create a custom property in a extended control, so that
I wanted to create a new property on a table in my model.. Basically
I want to create a custom property on one of my entities mapped from
In a WPF application, I can create an inherited property by using the FrameworkPropertyMetadata:

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.