Skip navigation.
 
mlRe: how to deal with files
FROM : Pascal Goguey
DATE : Sat Nov 23 00:15:54 2002

Hello,

Thanks for the reply! (and thanks to other people who also replied).

I have commented [Data release] and [Path release] but it crashes the
same way. I can follow everything in the debugger as long as I am in
WriteFile. When I leave WriteFile, The window appears, and it is
simply dead. It stays like this forever.
When I don't use the debugger, it exits lke this:

FileTest has exited due to signal 11 (SIGSEGV).

Tanks for any hint.

Pascal


On $BEZMKF|(B, 11 23, 2002, at 04:07 Asia/Tokyo, Jonathan E. Jackel wrote:

> Data is autoreleased when it is created.  You did not use alloc,
> copy, or
> new to create it, so you should not release it.  When you release it
> anyway
> at the end of WriteFile:, your program crashes.
>
> Incidentally, I believe initWithCString is deprecated.  There's no real
> point to using a C string in this context anyway.  Use
>
> Path = [NSString stringWithString:@"/Users/pascal/Desktop/helpfile"]
>
> Just remember the @.  You could even do
>
> Path = @"/Users/pascal/Desktop/helpfile"
>
> Either way, get rid of [Path release].
>
> Jonathan
>

>> - (IBAction)WriteFile:(id)sender {
>>     NSString * Path = [[NSString alloc]
>> initWithCString:"/Users/pascal/Desktop/helpfile"];
>>     NSData * Data = [NSData dataWithBytes:"help!\n" length:6];
>>     //    Create the file object if it does not exist yet
>>     if(mFileHandle == NULL) {
>>         //    Check if the file itself exists at the
>> specified path. If not,
>> create it
>>         NSFileManager * mFileManager = [NSFileManager
>> defaultManager];
>>         if([mFileManager fileExistsAtPath: Path] == NO) {
>>             [mFileManager createFileAtPath:Path
>> contents:nil attributes:nil];
>>         }
>>         //  Then at this point, the file exists physically
>> on the disk
>>         mFileHandle = [NSFileHandle
>> fileHandleForUpdatingAtPath:Path];
>>     }
>>     [mFileHandle seekToEndOfFile];
>>     [mFileHandle writeData:Data];
>>     [mFileHandle closeFile];
>>     [mFileHandle release];
>>     mFileHandle = NULL;
>>     [Path release];
>>     [Data release];
>> }
>>
>> @end

_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlhow to deal with files Pascal Goguey Nov 22, 17:52
mlRE: how to deal with files Marco Binder Nov 22, 18:35
mlRE: how to deal with files Jonathan E. Jackel Nov 22, 20:07
mlRe: how to deal with files Pascal Goguey Nov 23, 00:15