Re: loaded object: (0x0)
Re: loaded object: (0x0)
- Subject: Re: loaded object: (0x0)
- From: "Patrick M. Rutkowski" <email@hidden>
- Date: Wed, 12 May 2010 16:28:25 -0400
Assuming the "main_object" is set to "assign" instead of "retain" what
happens is:
1) The nib loads, and Apple's nib-loader code instantiates the object
from the nib file (call it foo)
2) Apple's nib loader code then calls [foo autorelease]
3) Apple's nib loader code then does "owner.main_object = foo" (which
does a raw assign)
4) The "foo" ends up having a retain count of 1, and being in the
autorelease pool, which means it doesn't leak; but it will live long
enough so I can use it
5) Doing "owner.main_object = something_else" will not break anything, obviously
END OF STORY! :-p
If you want to tell me there's a problem somewhere there, then please
point a specific step #, and be very descriptive; because I'm pretty
darn sure I have it right.
-Patrick
On Wed, May 12, 2010 at 4:21 PM, Gustavo Pizano
<email@hidden> wrote:
> MMM I dunno about that..
>
> now I got confused..
> setMainObject:(NSObject *)value{
> [main_opbecjt release];
> main_object = nil;
> [value retain];
> main_object = value..
> }
>
> thats how I see a retain setter property.
>
> please correct me if Im wrong.
>
> does the IBOutlet connection also retains?
>
> G.
>
> On May 12, 2010, at 10:14 PM, Rafael Cerioli wrote:
>
>> Ok, but I meant that if you use your setter setMain_object: afterward, your first main_object will be leaked, correct me if I'm wrong ?
>>
>>
>> Le 12 mai 2010 à 15:48, Patrick M. Rutkowski a écrit :
>>
>>> Nope, there's no leaks or bad accesses with the "assign" in the
>>> @property on main_object.
>>>
>>> main_object will end up having a retainCount of 1, and be in the
>>> autorelease pool, destined to be freed; it's all as I wanted.
>>>
>>> It's all in line with what's described in
>>> http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html
>>>
>>> On Wed, May 12, 2010 at 3:37 PM, Rafael Cerioli
>>> <email@hidden> wrote:
>>>> In addition, don't you need a retain policy for your main_object property ? I'm not sure of the behavior of the nib loading process, but in the best case I think you will have a leak there, in the worst case, a bad access.
>>>>
>>>> Rafael
>>>>
>>>> Le 12 mai 2010 à 14:57, Gustavo Pizano a écrit :
>>>>
>>>>> Hello Patrick,
>>>>>
>>>>> I don't know but I see weird the way you initialize the MyFilesOwner..
>>>>>
>>>>> Normally I would do ..
>>>>>
>>>>> MyFieOwner * owner = [[MyFileOnwer alloc] iniWithNibName:@"Test" nibBundle:nil];
>>>>>
>>>>> of course taking into mind that MyFileOnwer would be a NSViewController, which in your example is not.
>>>>>
>>>>>
>>>>> but your error is
>>>>>
>>>>> [
>>>>> NSBundle
>>>>> loadNibNamed: @"TestNib.xib"
>>>>> owner: owner
>>>>> ];
>>>>>
>>>>> it should be
>>>>>
>>>>>
>>>>> [
>>>>> NSBundle
>>>>> loadNibNamed: @"TestNib"
>>>>> owner: owner
>>>>> ];
>>>>>
>>>>>
>>>>> Gustavo
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On May 12, 2010, at 8:35 PM, Patrick M. Rutkowski wrote:
>>>>>
>>>>>> I'm so horribly confused about why the below sample project fails to
>>>>>> load the object from "TestNib.xib".
>>>>>>
>>>>>> I expect to print something like:
>>>>>> loaded object: (<SOME_POINTER_HERE>)
>>>>>>
>>>>>> But instead I just get:
>>>>>> loaded object: (0x0)
>>>>>>
>>>>>> Could someone help clue me in?
>>>>>>
>>>>>> Test Project: http://www.rutski89.com/static/TestApp.zip
>>>>>>
>>>>>> I could just be really tried today, did I make a silly type-o somewhere?
>>>>>> -Patrick
>>>>>>
>>>>>>
>>>>>> P.S.
>>>>>> I tried changing the "main_object" property from assign to retain, but
>>>>>> it didn't help.
>>>>>> _______________________________________________
>>>>>>
>>>>>> 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
>>>>>
>>>>> _______________________________________________
>>>>>
>>>>> 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
>>>>
>>>>
>>
>
>
_______________________________________________
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