__attribute__((NSObject)) not behaving as expected

2014-01-24 Thread Kevin Meaney
Building on and compiling for minimum system of 10.9. Xcode 5.0.1

Using ARC.

I have a property declared so:

@property (readonly, strong) __attribute__((NSObject)) CGContextRef 
context

I have a designatied initializer defined like so:

-(instancetype)initWithCGContext:(CGContextRef)theContext

The object is alloc'd and the init method is called immediately after the 
context is created. Immediately after the init method returns the context is 
released.

If in the implementation of the init method I have:

self-_context = theContext

Then the first time I try and access the context I get a memory access 
exception. If I replace that with:

self-_context = CGContextRetain(theContext);

Then I get a memory leak of the context when my object is destroyed.

If however I just declare my property like so:

@property (readonly) CGContextRef context;

And in the initializer I use:

self-_context = CGContextRetain(theContext);

And add a dealloc:

-(void)dealloc
{
CGContextRelease(self-_context);
}

Then everything works as desired.

I'd like to know what I'm doing wrong.

Kevin


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: __attribute__((NSObject)) not behaving as expected

2014-01-24 Thread David Duncan
Compiler folks could explain this better, but the root issue is that 
__attribute__((NSObject)) doesn’t do as much as you might expect given the way 
you’ve declared it. Its better in the long run to just not rely upon it.

On Jan 24, 2014, at 10:58 AM, Kevin Meaney k...@yvs.eu.com wrote:

 Building on and compiling for minimum system of 10.9. Xcode 5.0.1
 
 Using ARC.
 
 I have a property declared so:
 
   @property (readonly, strong) __attribute__((NSObject)) CGContextRef 
 context
 
 I have a designatied initializer defined like so:
 
   -(instancetype)initWithCGContext:(CGContextRef)theContext
 
 The object is alloc'd and the init method is called immediately after the 
 context is created. Immediately after the init method returns the context is 
 released.
 
 If in the implementation of the init method I have:
 
   self-_context = theContext
 
 Then the first time I try and access the context I get a memory access 
 exception. If I replace that with:
 
   self-_context = CGContextRetain(theContext);
 
 Then I get a memory leak of the context when my object is destroyed.
 
 If however I just declare my property like so:
 
   @property (readonly) CGContextRef context;
 
 And in the initializer I use:
 
   self-_context = CGContextRetain(theContext);
 
 And add a dealloc:
 
   -(void)dealloc
   {
   CGContextRelease(self-_context);
   }
 
 Then everything works as desired.
 
 I'd like to know what I'm doing wrong.
 
 Kevin
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
 
 This email sent to david.dun...@apple.com

--
David Duncan


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: __attribute__((NSObject)) not behaving as expected

2014-01-24 Thread Manfred Schwind
Does ist help, if you assign it this way instead:

self.context = theContext;

In your original code you're directly accessing the backed instance variable 
instead of going over the property, so maybe your property-declaration is 
ignored in this case.

Regards,
Mani

Am 24.01.2014 um 19:58 schrieb Kevin Meaney k...@yvs.eu.com:

 Building on and compiling for minimum system of 10.9. Xcode 5.0.1
 
 Using ARC.
 
 I have a property declared so:
 
   @property (readonly, strong) __attribute__((NSObject)) CGContextRef 
 context
 
 I have a designatied initializer defined like so:
 
   -(instancetype)initWithCGContext:(CGContextRef)theContext
 
 The object is alloc'd and the init method is called immediately after the 
 context is created. Immediately after the init method returns the context is 
 released.
 
 If in the implementation of the init method I have:
 
   self-_context = theContext
 
 Then the first time I try and access the context I get a memory access 
 exception. If I replace that with:
 
   self-_context = CGContextRetain(theContext);
 
 Then I get a memory leak of the context when my object is destroyed.
 
 If however I just declare my property like so:
 
   @property (readonly) CGContextRef context;
 
 And in the initializer I use:
 
   self-_context = CGContextRetain(theContext);
 
 And add a dealloc:
 
   -(void)dealloc
   {
   CGContextRelease(self-_context);
   }
 
 Then everything works as desired.
 
 I'd like to know what I'm doing wrong.
 
 Kevin
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/lists%40mani.de
 
 This email sent to li...@mani.de


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: __attribute__((NSObject)) not behaving as expected

2014-01-24 Thread Kevin Meaney
On 24 Jan 2014, at 19:02, David Duncan david.dun...@apple.com wrote:

 Compiler folks could explain this better, but the root issue is that 
 __attribute__((NSObject)) doesn’t do as much as you might expect given the 
 way you’ve declared it. Its better in the long run to just not rely upon it.

When you say the way I've declared it, you mean as a readonly property or is 
there just a better way to get the desired the result. I don't like the manual 
solution I described because it is really declared as an assign then goes and 
retains the context. So I'm not finding an answer I'm happy with and I can't 
believe others are not having the same problem.

Kevin


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: __attribute__((NSObject)) not behaving as expected

2014-01-24 Thread Kevin Meaney
On 24 Jan 2014, at 19:10, Manfred Schwind li...@mani.de wrote:
 Does ist help, if you assign it this way instead:
 
 self.context = theContext;
 
 In your original code you're directly accessing the backed instance 
 variable instead of going over the property, so maybe your 
 property-declaration is ignored in this case.

It's a readonly property which you can't assign to using the normal setter even 
in the init method.

Kevin


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: __attribute__((NSObject)) not behaving as expected

2014-01-24 Thread David Duncan

On Jan 24, 2014, at 11:12 AM, Kevin Meaney k...@yvs.eu.com wrote:

 On 24 Jan 2014, at 19:02, David Duncan david.dun...@apple.com wrote:
 
 Compiler folks could explain this better, but the root issue is that 
 __attribute__((NSObject)) doesn’t do as much as you might expect given the 
 way you’ve declared it. Its better in the long run to just not rely upon it.
 
 When you say the way I've declared it, you mean as a readonly property or is 
 there just a better way to get the desired the result. I don't like the 
 manual solution I described because it is really declared as an assign then 
 goes and retains the context. So I'm not finding an answer I'm happy with and 
 I can't believe others are not having the same problem.


Basically every reference needs to carry the attribute in order for the right 
thing to be done in all cases. I suspect most people aren’t having this problem 
because this particular attribute is not very well known or widely used.
--
David Duncan


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com