Re: NSScreen being autoreleased during loadNib()

"Jacky.Seraph Mu" <[email protected]> Fri, 31 May 2013 13:54:56 +0800
Newsgroups gmane.comp.macosx.devel
Message-ID <CACv8rU95KDtCx7wKnzGPkpcvJYiK3XgWak1xUXS3fcGVu07=MQ@mail.gmail.com>
Thank you for comment.

Then I still got 2 questions:
1. I saw the compiler reused the register for other purpose when I use -Os
in gcc to build. But in the instance, I set it to -O0. So I wonder if
compiler still did such optimization?

2. From the stack trace of gdb, I can see the an autoreleas-related action.
#4 0x00007fff8427c230 in (anonymous namespace)::AutoreleasePoolPage::pop ()
#5 0x00007fff8583cd72 in _CFAutoreleasePoolPop ()

So my question is that if the autorelease is added by compiler (while
building) because of the deference for other purpose? If so, how shall I
prevent this happening? I couldn't see the related action talked about on
apple's documents. Could you leave any links for this?


Thanks,

Jack


2013/5/31 Kyle Sluder <[email protected]>

> On Thu, May 30, 2013, at 06:46 PM, Jacky.Seraph Mu wrote:
> > After having executed the line "A Problem happens", I found that the
> > content of the screen (that is, the *screen) changed.
>
> No, what actually happened is that the stack space/register for `screen`
> was reused by the compiler, so `p *screen` dereferenced whatever value
> got stuffed in the former storage for `screen`. You got (un)lucky and
> this dereference didn't cause an access violation.
>
> --Kyle Sluder
>