A question about NSScreen being autoreleased during loadNib()
A question about NSScreen being autoreleased during loadNib()
- Subject: A question about NSScreen being autoreleased during loadNib()
- From: "Jacky.Seraph Mu" <email@hidden>
- Date: Tue, 28 May 2013 18:50:19 +0800
Hi,
I am OSX developer. The problem I encountered is described as below:
- (void)method1:(NSObject *)arg1
contextInfo:(NSObject *)arg2
{
...
[self method2:arg1
screen:[self.windowController window].screen];
...
}
- (void)method2:(NSObject *)arg1
screen:(NSScreen *)screen
{
...
MyWindowController *myWindowController =
[[MyWindowController alloc] initWithWindowNibName:@"MyWindow"];
NSWindow *aWindow = [MyWindowController window]; // A Problem happens
...
}
After executed the line "A Problem happens", I found that the content of
the screen (that is, the *screen) changed.
(gdb) p *screen
$15 = {
<NSObject> = {
isa = 0x7fff788a6598 xxxxxxxx changed
},
members of NSScreen:
_frame = {
origin = {
x = -4353346, xxxxxxx changed
y = -234234
},
size = {
width = -35252435, xxxxxxxx changed
height = -3452663, xxxxxxxx changed
}
},
_depth = 520,
_screenNumber = 2077752383,
_auxiliaryStorage = 0x0
}
At the very beginning, I thought there could have been a stack overflow or
memory corruption that resulted in this issue. But then I used gdb to watch
the when *screen is changed. And I also thought that perhaps due to a
memory corruption, screen has been released unexpectedly. So I also
rwatched the screen and *screen. But what I got is only that:
(Please forgive me changed some log because I cannot release the code here.)
#0 0x00007fff8427824f in objc_msgSend ()
#1 0x00007fff8c5748e4 in -[NSScreen dealloc] ()
#2 0x00007fff8581528a in CFRelease ()
#3 0x00007fff85852efc in -[__NSArrayI dealloc] ()
#4 0x00007fff8427c230 in (anonymous namespace)::AutoreleasePoolPage::pop ()
#5 0x00007fff8583cd72 in _CFAutoreleasePoolPop ()
#6 0x00007fff8c07c172 in loadNib ()
#7 0x00007fff8c07b88c in +[NSBundle(NSNibLoading)
_loadNibFile:nameTable:withZone:ownerBundle:] ()
#8 0x00007fff8c1ce5bc in +[NSBundle(NSNibLoading)
loadNibFile:externalNameTable:withZone:] ()
#9 0x00007fff8c20160b in -[NSWindowController loadWindow] ()
#10 0x00007fff8c2012e5 in -[NSWindowController window] ()
#11 0x000000010003c3c9 in -[SessionListener method2:screen:]
(self=0x10220caa0, _cmd=0x100261922, arg1=0x10209ede0, screen=0x1020b7d20)
at SessionListener.m:307
#12 0x000000010003d3f4 in -[SessionListener method1:contextInfo:]
(self=0x10220caa0, _cmd=0x1002618a0, arg1=0x10206b950, arg2=0x0) at
SessionListener.m:457
The rwatch and watch were set at the very beginning of the method2 being
executed.
Then I got the first break while executing the "A Problem happens"line with
above stack trace.
From my observing, the loading of the window seemed to trigger an
Autorelease cycle that released the NSScreen.
But I didn't do anything like autoreleasepool drain or release. So I
wondered why it happened that way.
The last thing is that, this issues doesn't always happen. It is very easy
to reproduce this issue on my 13 and 15 inch retina MBPs(OSX 10.8.2) but
cannot repro on my other 13 inch MBP non-retina (OSX10.8.2).
Could any one leave a comment?
Thanks,
Jack.Seraph
_______________________________________________
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