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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:44:06+00:00 2026-05-17T14:44:06+00:00

I archive an array (NSMutableArray) of custom objects that implement the . Once i

  • 0

I archive an array (NSMutableArray) of custom objects that implement the .
Once i load it froma file to a retaining property
@property (nonatomic, retain) NSMutableArray *buddies;
the release count of the object is 2 (correct, it’s 1of autorelease + 1 of retain of the property) but then noone releases it and the retain count becames 1, so when i release it i get
-[__NSArrayM retainCount]: message sent to deallocated instance
(i think because the 1 retain count is the autorelease)

Here’s the full code:

BuddieListViewController.h

#import <UIKit/UIKit.h>
#import "Buddie.h"

@interface BuddieListViewController : UITableViewController {
    IBOutlet NSMutableArray *buddies;
    [...]
}
[...]
@property (nonatomic, retain) NSMutableArray *buddies;
[...]
@end

BuddieListViewController.m

#import "BuddieListViewController.h"
#import "Buddie.h"
#import "PreviewViewController.h"

@implementation BuddieListViewController

@synthesize buddies;
[...]
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        [self loadFromDisk];
    }
    return self;
}

- (void)loadFromDisk {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0];
    NSString *appFile = [documentsPath stringByAppendingPathComponent:@"BuddieArchive.ark"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:appFile]) {
        self.buddies = [NSKeyedUnarchiver unarchiveObjectWithFile:appFile];
        NSLog(@"1- buddies retain count %d (should be 2, 1 + 1autorelease)", [buddies retainCount]);
    } else {
        self.buddies = [NSMutableArray arrayWithCapacity:1];
    }
}
[...]
- (IBAction)cancelledBuddie:(NSNotification *)notification
{
    [editingBuddie release];
    NSLog(@"2- buddies retain count %d (should be 2, 1 + 1autorelease)", [buddies retainCount]);
    [buddies release]; 
    [self loadFromDisk];
    [self.tableView reloadData];
}

Has anyone some idea of why this happens?

  • 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-17T14:44:07+00:00Added an answer on May 17, 2026 at 2:44 pm

    If you need to nullify the array, use the property accessor to set it to nil:

    self.buddies = nil;
    

    The synthesized implementation takes care of the memory management issues. Try to avoid sending -retain/-release messages directly to instance variables wherever possible and instead allow the property accessors to take care of things for you. It’ll save you a lot of trouble.

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

Sidebar

Related Questions

I am probably not seeing something here, that is why I am asking for
The iphone app I am creating has an array of commonly used settings. These
I've got some code which outputs a news archive sidebar. It all works very
And can you give me an example of an algorithm? alt text http://ryancalderoni.com/archive/ideal_curve.jpg EDIT:
How do i inverse the contents of NSArray in Objective-C? Assume that i have
I use Boost.Serialization to serialize a std::map. The code looks like this void Dictionary::serialize(std::string
I'm running in a problem with cakephp pagination. Currently, my pagination is rather standard.
I don't expect anyone to be able to help out with this but let's
I'm using Doctrine 1.2 as my ORM for a Zend Framework Project. I have
I have an e-commerce package called Prestashop. They allow you to sell virtual products,

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.