• 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
Re: Beginners question regarding NSFileHandle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Beginners question regarding NSFileHandle


  • Subject: Re: Beginners question regarding NSFileHandle
  • From: "R. Tony Goold" <email@hidden>
  • Date: Mon, 6 Aug 2001 18:28:40 -0400

> I have the following code, that causes a signal 10 (SIGBUS) error:
> {
> id fh;
>
> fh = [NSFileHandle fileHandleForReadingAtPath:@"/private/tmp/test"];
> if (fh == nil) {
> // do something
> }
> else {
> [fh readDataOfLength:3];
> [fh closeFile];
> [fh release];
> };
>
> }
>
> As soon as I leave '[fh release]' in the code I get the signal 10 error.
> Why?

Since fileHandleForReadingAtPath: is a convenience constructor (you didn't
call alloc to get it), the NSFileHandle it returns has probably been
autoreleased, so sending it a release message is an error. You only need
to send it a release message if you've previously sent it a retain message
or you created the object yourself using alloc.

> BTW: Is it possible to use the NSFileHandle type for fh instead of the
> generic id type ?

Yup. Just put:

NSFileHandle* fh = [NSFileHandle fileHandleForReadingAtPath:@"/private/
tmp/test"];


Cheers,
Tony


References: 
 >Beginners question regarding NSFileHandle (From: "Roger Gilliar" <email@hidden>)

  • Prev by Date: Wake and sleep notification
  • Next by Date: Re: Beginners question regarding NSFileHandle
  • Previous by thread: RE: Beginners question regarding NSFileHandle
  • Next by thread: Re: Beginners question regarding NSFileHandle
  • Index(es):
    • Date
    • Thread