Given the following code snippet from inside a method;
NSBezierPath * tempPath = [NSBezierPath bezierPathWithOvalInRect:pathRect];
[tempPath retain];
[path release];
[self setPath:tempPath];
Am I responsible for releasing tempPath
or will it be done for me?
The setPath is @synthesize
d so I probably would be able to leave out the [path release]
as well?
I know the better way of doing this is simply;
[path appendBezierPathWithOvalInRect:pathRect];
But, being new to Objective C and Cocoa, I'm trying to understand how things stick together.
---ADDED CONTENT
Leaving out the [tempPath retain]
results in a crash in the NSView
object that uses the paths.
The result from the debugger:
(gdb) po [0x145dc0 path] Program received signal EXC_BAD_ACCESS, Could not access
memory. Reason: KERN_PROTECTION_FAILURE at address: 0x00000021 0x93c56688 in objc_msgSend ()
CONFESSION OF GUILT - my mistake. Hope someone else will get something useful from my mistake. I had used assign
in place of retain
in the @property
declaration. Fixing those made the code work as expected.
THANKS FOR THE HELP GUYS