The following piece of code can be written in two ways. I would like to know what are the pros and cons of each. If possible I would like to stick with the one liner.
1)
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Background.png"]];
self.view.backgroundColor = background;
[background release];
2)
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Background.png"]];
Any issues with releasing memory etc. with #2? I’m new to Objective-C and would like to follow the best approach.
There is one more way that this can be written, and is commonly used for objects that do not need to be retained in memory:
This way, no memory management is needed.