Sporadic Crashing Problem

Friday, 2006-12-01; 02:00:00

another Cocoa programming problem I'm having trouble with

So here's another doozy that has recently cropped up and I can't seem to pin it down:

proposedLyrics = [[self getLyricsForCurrentTrack:currentTrackInfoDict] retain];
if (proposedLyrics == nil) {
        [proposedLyricsTextField performSelectorOnMainThread:@selector(setStringValue:) withObject:@"Lyrics not found" waitUntilDone:YES];
} else {
        [proposedLyricsTextField performSelectorOnMainThread:@selector(setStringValue:) withObject:proposedLyrics waitUntilDone:YES];

The problem: about 1 time in 10, the code crashes on one of the setStringValue calls. Here's the stack trace for the main thread:

#0      0xfffeff20 in objc_msgSend_rtp
#1      0x937291b0 in -[NSCell _setContents:]
#2      0x937290bc in -[NSCell setObjectValue:]
#3      0x93728fbc in -[NSActionCell setObjectValue:]
#4      0x93728c74 in -[NSCell setStringValue:]
#5      0x9373cd00 in -[NSControl setStringValue:]
#6      0x9296ea00 in __NSFireMainThreadPerform
#7      0x9080da78 in __CFRunLoopPerformPerform
#8      0x907dd4cc in __CFRunLoopDoSources0
#9      0x907dc9fc in __CFRunLoopRun
#10     0x907dc47c in CFRunLoopRunSpecific
#11     0x93208740 in RunCurrentEventLoopInMode
#12     0x93207dd4 in ReceiveNextEventCommon
#13     0x93207c40 in BlockUntilNextEventMatchingListInMode
#14     0x9370bae4 in _DPSNextEvent
#15     0x9370b7a8 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#16     0x93707cec in -[NSApplication run]
#17     0x937f887c in NSApplicationMain
#18     0x00011fa8 in main at main.m:13

This seems to indicate to me that it's a memory management problem -- something is getting over-released. But what's curious is that it also happens when I pass the static string "Lyrics not found". So it doesn't seem possible that the string that is being sent to the text field could possibly be overreleased. (I even tried creating a temp string and retaining it so as to create a memory leak, but the problem still happens.)

I believe all user interface actions have to happen on the main thread (otherwise I get problems with text fields getting garbled), but then why is this happening? I also tried changing these lines so that they run in the current thread, but that just shifted the problem elsewhere to another similar call.

Any ideas would be greatly appreciated. I haven't received any useful information from the cocoa-dev Apple mailing list.

Technological Supernova   Software Development   Older   Newer   Post a Comment