Thursday, September 8, 2011

objective-c: Do I have to release parameter objects or variable?

I was confused on this until I just realized that if the case is,

-(NSString*)name:(NSString*) _name {
    // I thought I need to do like [_name release];
    return _name;

So instead, the _name paramater object anyway is being reference, so ideally, the releasing of the object from memory is outside, i.e. from the callers perspective.


NSString *stupid = @"Johnny Bravo";
[name setName:stupid];
[stupid release];

or I can do autorelease anyway.

No comments: