• 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
Threading, save panels, and segfaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Threading, save panels, and segfaults


  • Subject: Threading, save panels, and segfaults
  • From: Charles Srstka <email@hidden>
  • Date: Fri, 9 Nov 2001 23:57:45 -0600

I have had a non-reproducible periodic crash that is driving me nuts. Using NSLogs, I have traced it to a line of code that is straightforward enough that I can't imagine how it could cause a segfault, but it does...

Here's the code where the crash occurs:

- (void)<the name of this particular method>
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSSavePanel *sp;
int answer;
NSNumber *i;
NSEnumerator *fileEnum = [outlineView selectedRowEnumerator];

<various other variable declarations>

while (i = [fileEnum nextObject])
{
PackageItem *fileToSave = [outlineView itemAtRow:[i intValue]];
NSString *pathToExtract = [fileToSave filename];
NSLog(@"pathToExtract is %@\n",pathToExtract);
// the previous line works, so I know that pathToExtract is good and
// isn't causing the problem
NSLog(@"Before save panel\n");
sp = [NSSavePanel savePanel];
NSLog(@"Before run modal\n");
// the next line is where it crashes!
answer = [sp runModalForDirectory:NSHomeDirectory() file:pathToExtract];
NSLog(@"After run modal\n");

<more stuff, not relevant to this>

Some notes:

The crash is sporadic and only occurs once in a while. Therefore, I can't reproduce it.

It may be relevant that this method is being run in a new thread, using:

[NSThread detachNewThreadSelector:@selector(<the method name>) toTarget:<the object the method is in> withObject:nil];

I don't understand how threading this could cause a segfault when opening a save panel, but then, I'm a newbie and could be missing something. I do like the program being multi-threaded, though, so if there's a way to keep the threading while eliminating the crash, I would like to know how to do it.

One other thing that may be relevant is that every once in a while I get error messages at the console of the following type:

*** _NSAutoreleaseNoPool(): Object <some hex number> of class <insert one of the following: NSCFString, NSPathStore2, NSCalibratedRGBColor, NSConcreteAttributedString> autoreleased with no pool in place - just leaking

I find this odd since I'm using an NSAutoreleasePool in every method that I'm spawning in a new thread. Also, some of the objects that are leaking (such as NSCalibratedRGBColor) seem like objects that UI elements would use, definitely not anything I'm using directly.

Please forgive me if this question has been asked before or has an obvious answer. I would be very appreciative if anyone has any insights as to why this could be occurring.

Thanks,
Charles Srstka


  • Follow-Ups:
    • Re: Threading, save panels, and segfaults
      • From: "Erik M. Buck" <email@hidden>
  • Prev by Date: Re: workspaces and capturing keystrokes
  • Next by Date: Re: Cocoa sheets using Java
  • Previous by thread: Re: NSScrollView's non-scrollbar section
  • Next by thread: Re: Threading, save panels, and segfaults
  • Index(es):
    • Date
    • Thread