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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:43:03+00:00 2026-06-13T11:43:03+00:00

// AClass.m // init enemyBullets = [[NSMutableArray alloc] initWithCapacity:0]; enemy1 = [[Enemy alloc] initWithBullets:enemyBullets];

  • 0
// AClass.m
// init
enemyBullets = [[NSMutableArray alloc] initWithCapacity:0];
enemy1 = [[Enemy alloc] initWithBullets:enemyBullets];

// At some point
NSMutableArray *bulletsToDelete = [NSMutableArray array];
for(BulletEnemy *thisBullet in enemyBullets)
{
    // If I have to delete
    [bulletsToDelete addObject: thisBullet];
}
[enemyBullets removeObjectsInArray:bulletsToDelete];

//dealloc method
[enemyBullets release];
[enemy1 release];

Now Inside Enemy some point in time I do the following:

// Enemy.m
- (id)initWithBullets:(NSMutableArray*) _bullets{
     // Enemybullets is a var of Enemy
     enemyBullets = _bullets;
}

// At some point...
myBullet = [[BulletEnemy alloc] init];
[enemyBullets addObject:myBullet];
[myBullet release];

The problem is when I do the following at Aclass:

[enemyBullets removeObjectsInArray:bulletsToDelete];

The dealloc method inside BulletEnemy doesn’t get called because the retain count isn’t 0. Why? But If I release ACLass (which releases enemyBullets) then My bullets get deallocated.

  • 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-13T11:43:04+00:00Added an answer on June 13, 2026 at 11:43 am

    Aparently, I was asigning something with retain propery, which made the object +1 thus not to deallocate. Just changed the propery to assign and it worked.

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

Sidebar

Related Questions

-(id)init { if (self = [super init]) { self.name = [[NSString alloc] init]; self.type
I have a class: function RustEditor() { this.init = function() { var saveButton =
I have a class structure like abstract class Animal { public Animal(){ //init stuff..
I have created a class derived from NSImageView. However, the classes's constructor (init) is
Ie, if I have a class MyClass, and I do super(MyClass). init , how
Hi I am converting some prototype javascript to jQuery javascript. In prototype we can
I've a class that has some callbacks and its own interface, something like: class
When I initiate a class in Python, I give it some values. I then
For example, I am now learning wxPython, specifically a class' init function: __init__(self, parent,
I have a general question about writing init methods in Objective-C. I see it

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.