What is the difference between the Fraction *answer object and the origin object in these two code examples?
What I'm trying to figure out is where did I release (or was supposed to
) release the *answer pointer? Does releasing the myFract object in main take care of the pointer in the add method? I feel like I'm missing a fundamental point about memory allocations
The origin object is created in the setOrigin method, so we have to deallocate it there as well, but why not [Fraction *answer]?
-(Fraction *) add: (Fraction *) f
//Tp add two fractions:
// a/b +c/d = ((a * d)+(b * c)) / (b * d)
Fraction *answer = [[Fraction alloc] init];
answer.numerator = (numerator * f.denominator) + (denominator * f.numerator);
answer.denominator = denominator * f.denominator;
-(void) setOrigin: (XYPoint *) pt
origin = [[XYPoint alloc] init];
[origin setX: pt.x andY: pt.y];