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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:59:26+00:00 2026-05-23T01:59:26+00:00

I am struggling in iOS (4) with allocating objects in one scope and releasing

  • 0

I am struggling in iOS (4) with allocating objects in one scope and releasing it in another scope. I am using properties as pointers to the objects. The object is allocated and initialized in one instance class method and I release it in the class’ dealloc method. The properties are declared with retain. Besides having problems with using properties likes this I also find it cumbersome to alloc and initialize the object and set the property.

NSObject *object = [[NSObject alloc] init];
Self.myProperty = object;
[object release];

I tried

self.myObject = [[NSObject alloc] init];

However that gave me a memory leak.

My question: Do I have to make this temporary object or is there a more elegant way of doing this?

A followup question: Do I have to both set the property to nil and release the autogenerated ivar?

[self setMyProperty:nil], [myProperty release];

When XCode 4 generates property stubs for you it puts [self setMyProperty:nil] in viewDidUnload and [_myProperty release] in dealloc.

  • 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-23T01:59:26+00:00Added an answer on May 23, 2026 at 1:59 am

    First question:

    autorelease is your friend:

    self.myObject = [[[NSObject alloc] init] autorelease];
    

    Second question:

    No, it’s redundant, but harmless since the second operation will do nothing ([nil release] is safe).
    I’d advise using the self.XXX = nil; construct, as it’s safer and very clear/readable.

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

Sidebar

Related Questions

I am using two managed object contexts in my iOS app. The first context
I am very new at iOS and objective-c development, so I am struggling with
Been struggling with replacing a backslash by another symbol such as '.-.' just to
I'm using a StoryBoard which contains various ViewControllers and a TableViewController, one in particular
I'm struggling with file handling on iOS. I could already assign my file type
Im struggling with some iOS development and I hope someone will be able to
I am a novice to IOS programming hence struggling a bit with the below
I have created an application using the new Twitter framework in iOS 5, however
I am trying to port one of my iOS applications to Mac OS X,
I have compiled and built openssl to my iOS project, but struggling in objective-c

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.