Re: iPhone: NSFileManager/NSDirectoryEnumerator Crash?
Re: iPhone: NSFileManager/NSDirectoryEnumerator Crash?
- Subject: Re: iPhone: NSFileManager/NSDirectoryEnumerator Crash?
- From: Jeffrey Walton <email@hidden>
- Date: Fri, 11 Mar 2011 06:20:22 -0500
Hi Andreas,
Sorry about the TP. I only wanted to hit one item.
> So, I suspect the error is elsewhere, it may be "thread-related" if
> you do such things - but it's most likely still in your code ;)
You were right - a simple 'Hello World' worked as expected. I'll have
to look for the issue in other places. I'm not threading at this
point, which leads me to beliew I've got a problem with my view stack.
Thanks for taking the time.
Jeff
On Fri, Mar 11, 2011 at 4:27 AM, Andreas Grosam <email@hidden> wrote:
>
> On Mar 10, 2011, at 1:33 AM, Jeffrey Walton wrote:
>
>> Hi All,
>>
>> I've got a method that refreshes a list of files in a directory. The
>> code executes properly on the first invocation, but crashes on the
>> second invocation. The cause of the crash is walker = [fileManager
>> enumeratorAtPath:directory].
>>
>> Any ideas on the cause? I experience the crash with both methods of
>> retrieving the file manager. Are there known issues with
>> enumeratorAtPath?
>
> Form the snipped below, I cannot see a memory management error. It doesn't mean, there is none, though. The object 'walker' *should* be valid unless you access it *after* you released 'fileManager'.
>
> It not at all looks like a concurrency issue or race condition related problem stemming from the framework. If there is an issue in the framework, it may only happen when you simultaneously alter the contents of the directory in a different thread while you iterating through it in your code.
>
> So, I suspect the error is elsewhere, it may be "thread-related" if you do such things - but it's most likely still in your code ;)
>
> Nonetheless, after you carefully reviewed your code, and couldn't find the error I would resort to check a thread-safety related issue within Cocoa as well.
>
>
> Andreas
>
>>
>> Jeff
>>
>> NSString* directory = nil;
>> NSFileManager* fileManager = nil;
>> NSDirectoryEnumerator* walker = nil
>>
>> directory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
>> if(directory == nil)
>> /* handle error and exit */
>>
>> // fileManager = [NSFileManager defaultManager];
>> fileManager = [[NSFileManager alloc] init];
>> if(fileManager == nil)
>> /* handle error and exit */
>>
>> walker = [fileManager enumeratorAtPath:directory];
>> if(walker == nil)
>> /* handle error and exit */
>>
>> NSString* file = nil;
>> while((file = [walker nextObject]) != nil)
>> {
>> BOOL isDirectory = YES;
>> if([fileManager fileExistsAtPath:file
>> isDirectory:&isDirectory] && !isDirectory)
>> [files addObject:file];
>> }
>>
>> ...
>>
>> [fileManager release];
>>
>> *****
>>
>> According to 'NSFileManager Class Reference'
>> (http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html):
>>
>> In iOS and Mac OS X v 10.5 and later you should consider
>> using [[NSFileManager alloc] init] rather than the singleton
>> method defaultManager. Instances of NSFileManager are
>> considered thread-safe when created using
>> [[NSFileManager alloc] init].
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden