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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:25:22+00:00 2026-05-16T10:25:22+00:00

-(void)LoadOriginalListFromFile { NSMutableArray *temp; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths

  • 0
-(void)LoadOriginalListFromFile
{

NSMutableArray *temp;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *path = [documentsDirectory stringByAppendingPathComponent:@"shopes.dat"];
//2.check if file exists
NSFileManager *fileManager = [NSFileManager defaultManager];
if([fileManager fileExistsAtPath:path]) 
{
    //open it and read it 
    NSLog(@"shopes.dat file found. reading into memory");
    NSMutableData *theData;
    NSKeyedUnarchiver *decoder;
    //3. decode the file into memory
    theData = [NSData dataWithContentsOfFile:path];
    decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData];
    temp = [[NSMutableArray alloc]init];
    temp = [decoder decodeObjectForKey:@"m_OriginalArray"];

    //4. add object to original list
    NSEnumerator *enumerator = [temp objectEnumerator];
    id anObject;

    while (anObject = [enumerator nextObject]) 
    {

        [m_OriginalArray addObject:anObject];
    }

    //[temp release];   // here is the problem!!!!!
    [decoder finishDecoding];
    [decoder release];

}
else
{
    NSLog(@"shopes.dat file not found");
}

}

I have problem with the temp object.
what i want to do is to release the object before the function end but if i do so when the app is launch i get ERROR_BAD_ACSS , i cant understand why?
i alloc the temp object then i add all the objects in the temp array to my m_OriginalArray i also tryied to retain the objects but no lack.

  • 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-16T10:25:23+00:00Added an answer on May 16, 2026 at 10:25 am

    You’re creating “temp” twice here. First you’re alloc/init’ing it, in which case the release would make sense. But then that instance is getting discarded, and replaced with the return value from [decoder decodeObjectForKey: @”m_originalArray”]. That new instance is autoreleased, and so when you release it manually, you’re setting it up to crash when the autorelease pool drains. Simply get rid of the first assignment, and the matching release, and you won’t leak or crash.

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

Sidebar

Related Questions

- (void)viewDidLoad{ [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@VidName ofType:@mov]; NSURL *url =
- (void) showMail { [[CCDirector sharedDirector] pause]; NSString*myemail=@sirano0629@me.com; NSArray*email=[[NSArray alloc]initWithObjects:myemail, nil]; if([MFMailComposeViewController canSendMail]) {
- (void)loadLocations { NSString *url = @<URL to a text file>; NSStringEncoding enc =
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint
- (void)viewDidLoad { moveObjectTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(moveObject) userInfo:nil repeats:YES] -(void)moveObject image.center =
- (void)viewDidLoad { webCollectionOnScroller=[[NSMutableArray alloc] init]; scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 370, 320, 94)];
-(void)setUserFilters{ //init the user filters array userFilters = [[NSMutableArray alloc] init]; SearchCriteria *tmpSc= [[SearchCriteria
void addNewNode (struct node *head, int n) { struct node* temp = (struct node*)
- (void)viewDidLoad { [super viewDidLoad]; definedNames = [[NSArray alloc] initWithObjects:@Ohio, @Newark, @Steve, @Coffee, nil];
void sortAlphabetically(int listLength, contactInfo* arrayOfStructs) { contactType temp; for (int i = 0; i

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.