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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:05:35+00:00 2026-06-03T11:05:35+00:00

If I have ClassA.h 1.@property (nonatomic, retain) NSMutableArray *arr; ClassA.m -(ClassA) function { 1.ClassA

  • 0

If I have
ClassA.h

1.@property (nonatomic, retain) NSMutableArray *arr;

ClassA.m

-(ClassA) function {

    1.ClassA *obj = [[ClassA alloc] init]; 
    // initialize the arr
    // add another object into the arr
    2. [obj.arr addObject:nameOfAnObject]
    3. return obj; 

}

at ClassB, I want to call (ClassA) function method.What I do is

ClassB.m

-(void)viewDidload {

  1.[super viewDidLoad];
  2.ClassA     *classAinB = [[classA alloc] init];                                                                        
  3.classAinB = [classA function];
  4.[classAinB release];

}

According the rule of memory management,because I own a ClassAinB in ClassB.m, so I free it at the end.

My question is how is the var ClassA which I own in ClassA.m, when should I release it so that after a call back at line 3 of ClassB, I still have the object of ClassA whose arr is containing nameOfAnObject object

Please advice me on this issue. Any comments are welcomed here. Thanks

  • 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-03T11:05:36+00:00Added an answer on June 3, 2026 at 11:05 am

    Add it to the autorelease pool. i.e. return [obj autorelease];. This will make sure the object is sent a release message at the end of the run loop iteration if it no longer has any owner.

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

Sidebar

Related Questions

I have a class wich is initialized like this. // myclass.h @property(nonatomic,retain) NSMutableArray *daysOfWeek;
I have class named Building : @interface Building : NSObject @property (nonatomic,retain)NSString* node; @property
I have @property(nonatomic,retain) UIPopoverController * popoverController; I create my popover in my implementation class.
If I have an IEnumerable where ClassA exposes an ID property of type long.
D2.0 classes have a __monitor class property that gives access to the class object's
I have a class with a Property called 'Value' which is of type Object.
I have a class: class MyClass(object): @property def myproperty(self): return 'hello' Using mox and
I have a method to generate a Deck object (NSObject subclass with an NSMutableArray
In rootViewController.h i have a property NSMutableArray mainList: @interface RootViewController : UITableViewController { NSMutableArray
I want to have a class property that allow for an expression to take

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.