Re: Beginners question regarding NSFileHandle
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