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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:46:08+00:00 2026-05-23T11:46:08+00:00

What if I want to alloc a class inside another and I want to

  • 0

What if I want to alloc a class inside another and I want to reference it easily, but sometimes this class would not need to be alloc’d, therefore not dealloc’d. How is this done? Can I put a conditional inside dealloc so it doesn’t have to be released?

In more detail, I’m using Cocos2D. I have player ability classes that may or may not need to be allocated. In my init:

    // Abilities
    if(abilityRushH == 0){
        objects = [theMap objectGroupNamed:@"oj"];
        startPoint = [objects objectNamed:@"item_ability_rushH"];
        x = [[startPoint valueForKey:@"x"] intValue];
        y = [[startPoint valueForKey:@"y"] intValue];

        rushH = [[RushHorizontal alloc] init];

        [self addChild:rushH.rushHSpriteSheet];

        rushH.rushHSprite.position = ccp(x,y);              
    }

    if(abilityRushV == 0){
        objects = [theMap objectGroupNamed:@"oj"];
        startPoint = [objects objectNamed:@"item_ability_rushV"];
        x = [[startPoint valueForKey:@"x"] intValue];
        y = [[startPoint valueForKey:@"y"] intValue];

        rushV = [[RushVertical alloc] init];

        [self addChild:rushV.rushVSpriteSheet];

        rushV.rushVSprite.position = ccp(x,y);  
    }

Cocos2D needs to keep the reference so it can scroll with the map. But if I’m not alloc’ing it, how do I NOT 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-23T11:46:09+00:00Added an answer on May 23, 2026 at 11:46 am

    Since you are talking of releasing it in dealloc, there will be an instance variable for this. Now when any instance of an Objective-C class is allocated, all its objects are nil and c types are set to 0 (or equivalent values). So you don’t need to put any extra effort if the object of your class isn’t instantiated as the instance variable will be nil at dealloc and so release message sent to it will have no effect.

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

Sidebar

Related Questions

I want to define a class that supports __getitem__ , but does not allow
I want to implement a generic method on a generic class which would allow
I'm want to put a tableView inside a UIViewController, because I need a toolbar
I want to set the delegate of an object inside a class method in
I have an UITextField inside an UITableViewCell. I want the textField to return but
I want to have a class property that allow for an expression to take
I am using the code: { randomstatus=0; msg=[[NSString alloc]initWithFormat:@Good job, do you want to
I want to allow a user to drag my Win32 window around only inside
I want to detect existence of a specific member function for a class, using
I'm having a class with 2 pure virtual methods and another class which needs

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.