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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:46:56+00:00 2026-06-13T23:46:56+00:00

*beginner iOS programmer, please explain with patience suppose i have 2 classes – Foo,

  • 0

*beginner iOS programmer, please explain with patience

suppose i have 2 classes – Foo, Bar

in class Bar, i have a pointer to an instance of Foo, which i set during init. (and because i dont know how to properly import Foo and Bar with each other, i end up setting the type to id instead of Foo)

@implementation Bar{
    id pointerToInstanceOfFoo;
}

how do i write my dealloc function for Bar? or DO I even override the dealloc function?

right now i have

-(void)dealloc{
    pointerToInstanceOfFoo = NULL;
    [super dealloc];
}

i still want that pointer to Foo to be around when Bar dies, but am i doing things right? several questions:

  1. if Foo and Bar imports from each other, how do i do this? or is this bad software design?
  2. right now i have the pointer “pointerToInstanceOfFoo” set in the @implementation… is this equivalent to declaring a private pointer in class Bar?
  3. should i instead be using
    @property (nonatomic, weak) id pointerToInstanceOfFoo
    instead? if so, why do i keep getting this error about no weak pointers in ARC?
  4. do i need
    delete pointerToInstanceOfFoo;
    in the dealloc function??

Sorry for the confusion, any explanations/answers would be greatly appreciated!!

P.S. i’m using XCode 4.4 and running on iOS 5.0 with cocos2d v2.1 beta… i think it’s using arc

  • 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-13T23:46:57+00:00Added an answer on June 13, 2026 at 11:46 pm

    You are not allowed to use [super dealloc] in ARC. So if that compiles, you are not using ARC and you need cals to retain and release. Writing a whole tutorial on that is not something that will fit in a stack overflow answer. As for your other questions:

    1) Just import them in the implementation file, not the header file.

    2) Yes

    3) If it makes you happy. The error probably means you are targeting below iOS 5.0 (I.e. the deployment target in your project settings is set to less than 5.0), in which weak pointers are not supported, or ARC is turned off. I don’t think you’ve accurately reported the error message since it makes no sense.

    4) “delete” is not valid objective-c or valid c.

    P.S. No, you don’t want that pointer to be around after Bar is deallocated because that would be a memory leak. Perhaps you want a static variable instead of an instance variable?

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

Sidebar

Related Questions

Beginner iOS dev here. I have a problem in my array. Im making an
I'm a beginner in iOS development and I have to put in the same
Please provide me some iOS game development documentation for beginners. I do already have
I am an iOS newbie, so please pardon me if this is a beginner
I am a beginner to iOS development and have just started working with the
I am a beginner in iOS development and have just start using the lasted
iOS beginner here. I have the following code: [facebook authorize:nil delegate:self]; NSString *string1=[facebook accessToken];
I am a beginner in iOS development. I have got some understanding on provisioning
Hi I am beginner to iOS and I have a question. I want to
I am a beginner iOS programmer. I would like to know what is the

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.