Re: Newbie question: chrash on [tableview reloadData]
Re: Newbie question: chrash on [tableview reloadData]
- Subject: Re: Newbie question: chrash on [tableview reloadData]
- From: Terje Tjervaag <email@hidden>
- Date: Thu, 21 Nov 2002 20:30:51 +0000
Thanks to you who have replied. I have now found the exact source of
the crash. From the source code listed below, if I comment out the
[dirEnumerator release] line, like I have done below, the app runs
fine. I suppose then I am not meant to touch the NSDirectoryEnumerator
after I have created it, but I really don't understand why this is
affecting my NSMutableArray 'files' after I have finished filling it
with filenames from the directory
enumerator. Anyone care to explain?
NSDirectoryEnumerator *dirEnumerator = [[NSFileManager defaultManager]
enumeratorAtPath:[path stringValue]];
NSString *currentName;
TTGraphicFile *tempFile;
while (currentName = [dirEnumerator nextObject]) {
tempFile = [[TTGraphicFile alloc] init];
[tempFile setFileName:currentName];
[tempFile setFileSize:34];
[files addObject:tempFile];
[tempFile release];
}
// Make sure objects are released
//[dirEnumerator release];
//[currentName release];
// Refresh table
[self updateUI];
Thanks again!
Terje
ps. I DO generally post code when I ask people questions, but in this
case it was a bit hard since I had really no idea of the source of the
problem. Hopefully my cocoa/Objective-C skills will be refined enough
to ask some SENSIBLE questions soon! ;-)
On Thursday, November 21, 2002, at 07:25 PM, Fritz Anderson wrote:
Seeing your document's source code would be helpful, but my guess
would be that when the NSTableView tries to redisplay your data, your
NSMutableArray has been released, and the pointer is noo longer valid.
Is it possible you are getting the NSMutableArray by one of the
convenience methods like [NSMutableArray arrayWithObjects:...] or
[NSMutableArray arrayWithCapacity:...]? If so, the resulting pointer
is autoreleased, and will become invalid when the call chain in which
it was created returns. You should either retain that pointer, or
obtain a retained pointer with initializers like [[NSMutableArray
alloc] initWithObjects:...], etc.
-- F
On Thursday, November 21, 2002, at 11:14 AM, Terje Tjervaag wrote:
I am working through Aron Hillegass' book Cocoa Programming for Mac
OS X
...
I have made my own little file class, containing two strings, the
file name and a description. The application is a document
application and in my document init method I can create a new file
and insert it into the NSMutableArray I use as the datasource for the
tableview. When the application loads it displays this row fine, but
when I try to call reloadData AFTER that, even though I have not
added any objects to my array, the application crashes with a "due to
signal 10 (SIGBUS)".
Does anyone have ANY clue as to what can be causing this? I would
give you more details, but I haven't got a clue whats going on here.
_______________________________________________
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.