Having coded for many years in everything from Python to 6502 assembler, I'm finally learning Objective C.
Obviously, memory management is the big 'huh?' at the moment, so I was wondering if anyone had time to help me understand what's going on in the little code snippet below.
Given a class 'Head', and a class 'Human' defined elsewhere, I tried allocating a new Head for the Human in two different ways:
1) this is the way I like to code, but it leaves a permanently inflated retain count (as far as I can tell from my NSLog-ing):
human.head = [[Head alloc] init];
2) whereas this does not:
Head *head = [[Head alloc] init];
human.head = head;
[head release];
I'm well aware that there was no 'release' called in 1), but it seems odd if a one-line creation/assignment of this sort isn't treated as an auto-release.
Many thanks - especially if this is a really stupid question.
Obviously, memory management is the big 'huh?' at the moment, so I was wondering if anyone had time to help me understand what's going on in the little code snippet below.
Given a class 'Head', and a class 'Human' defined elsewhere, I tried allocating a new Head for the Human in two different ways:
1) this is the way I like to code, but it leaves a permanently inflated retain count (as far as I can tell from my NSLog-ing):
human.head = [[Head alloc] init];
2) whereas this does not:
Head *head = [[Head alloc] init];
human.head = head;
[head release];
I'm well aware that there was no 'release' called in 1), but it seems odd if a one-line creation/assignment of this sort isn't treated as an auto-release.
Many thanks - especially if this is a really stupid question.