Re: Multithreading/Memory Management Problem
Re: Multithreading/Memory Management Problem
- Subject: Re: Multithreading/Memory Management Problem
- From: Tommy Nordgren <email@hidden>
- Date: Wed, 29 Nov 2006 23:21:26 +0100
On 29 nov 2006, at 20.11, Simone Manganelli wrote:
I'm having a weird problem with a multithreaded application that
I'm creating. Here's a small snippet of code from the application,
which runs in a spun-off thread.
proposedText = [[self getTextForCurrentTrack:infoDict]
retain]; // gets some text that's to be displayed in a window
if (proposedText == nil) {
[proposedTextTextField performSelectorOnMainThread:@selector
(setStringValue:) withObject:@"Text not found" waitUntilDone:YES];
} else {
[proposedTextTextField performSelectorOnMainThread:@selector
(setStringValue:) withObject:proposedText waitUntilDone:YES];
}
Regardless of whether proposedText ends up initially being nil or
not, I sometimes get a crash on either line where I set the
stringValue of an NSTextField. It doesn't happen all the time --
it happens about one time out of 10 or so. (I was under the
impression that all user interface actions, like setting the
stringValue of a visible text field, needed to be done on the main
thread. I've experienced problems with text fields getting garbled
if I don't do this.)
The crash seems to be some kind of memory management issue, where
something gets over-released. However, given that the crash occurs
both on the setStringValue line in the case of proposedText not
being nil, AND in the case where proposedText is nil, I don't see
how I could possibly be over-releasing anything -- in the latter
case, I'm passing a static string to the text field, not a variable
that could have been over-released.
When having problems with multiple threads and memory, One possible
cause to consider, is
wether there is a retain/release Race Condition
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 say that the string variable that I'm passing to the
text field is being over-released, but as I said above, how is that
possible? Also, why is the problem only occurring very rarely, and
not every time?
Any help would be greatly appreciated.
-- Simone
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
40chello.se
This email sent to email@hidden
------
What is a woman that you forsake her, and the hearth fire and the
home acre,
to go with the old grey Widow Maker. --Kipling, harp song of the
Dane women
Tommy Nordgren
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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