• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
autorelease problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

autorelease problem


  • Subject: autorelease problem
  • From: Hok Chun So <email@hidden>
  • Date: Wed, 10 Jul 2002 11:25:35 +0800

Dear all,

I am new to Cocoa. I written my own code to try NSArchive and NSUnarchive.

However, I encounter some problem about autorelease.

Below is the code extract:

- (IBAction)showInfo:(id)sender
{
NSString *filePath;
int i = 0;
// create a text string
myStr = [[MyString alloc] init];
// save string into a file under current user's home directory
filePath = [NSHomeDirectory() stringByAppendingPathComponent:@"testfile"];
if ( [NSArchiver archiveRootObject:myStr toFile:filePath] == YES )
i = 1;
// read back the file
[myStr autorelease]; // ************ problem occurs here
myStr = [NSUnarchiver unarchiveObjectWithFile:filePath];
[myStr retain];
// display the string onto text panel
[textPanel setString:[[myArchiveStr getDate] description]];
}

myStr is an instance variable. I tried to archive it and unarchive it in the same action function.

However, after archiving myStr, program runs [myStr autorelease] and the program exit abnormally.

The program receives the following signal: "SIGABRT"
the call stack:
0 kill
1 abort
2 _objc_fatal
3 abort
4 _freeHandler
5 NSPopAutoreleasePool
6 -[NSAutoreleasePool release]
7 -[NSApplication run]
8 NSApplicationMain
9 main
10 _start
11 start

Can you tell me why the autorelease causes this problem? The program runs normally if I comment out [myStr autorelease].

Thanks for your help.

Bill
Computer Engineering Student, University of Hong Kong
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: autorelease problem
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Re: Database Suggestions
  • Next by Date: Re: Linking Mach-O and AIX binaries
  • Previous by thread: Re: "Morphing" Sheets
  • Next by thread: Re: autorelease problem
  • Index(es):
    • Date
    • Thread