Review request for MACOSX_PORT-176: AWT Splashscreen support
Mike Swingler
swingler at apple.com
Thu Dec 15 12:26:59 PST 2011
On Dec 15, 2011, at 6:40 AM, Anthony Petrov wrote:
> On 12/15/11 07:39, Mike Swingler wrote:
>> On Dec 12, 2011, at 7:19 AM, Anthony Petrov wrote:
>>
>>>> Also, the QueuingApplicationDelegate should hold onto it's own NSMutableArray and real delegate as ivars, not global statics.
>>>
>>> I agree, and I made the queue an instance variable. However, as soon as I'm trying to access an ivar from a block, I get crashed. So I left the realDelegate static.
>>
>> Well, that's your first indication that something is wrong with the memory management. The ivar should be properly retained and released (converting it to an @property with an @sythesize can help with that), and the "self" should be retained by the block when it is copied to the callstack of the AppKit thread, and subsequently released when the block is finished.
>
> I assume that when I create a block, it retains 'self' reference to the outer object automatically, right? Moreover, I've even tried to do something like this:
>
> QAD qad = self;
> [... addObject:^(){
> // use 'qad' instead of 'self' in the block
> }];
>
> with no luck.
>
> I can't retain the ivar when I create the block since the realDelegate becomes known only later. But if my previous assumption is correct, then the block (I would assume) could access the ivar through the previously retained reference to 'self' with ease. (and certainly, the reference to realDelegate itself isn't released during executing the block). So why would it crash then? Note that it crashes when just reading the value of the ivar, like fprintf(..., (void*)(self->realDelegate)); - boom, it crashed! You don't even need to try calling a selector from it - you won't be able to read the ivar itself in the first place.
>
> I don't see how using @property/@synthesize might help with this issue.
Making the iVar a property will automate the retain/release semantics (so you don't have to write them), and will also assure atomicity when setting/getting the property value. The only thing you need to do is self.prop = nil in the -dealloc of the parent object.
Regards,
Mike Swingler
Apple Inc.
More information about the macosx-port-dev
mailing list