NSMutableArray *a1 = [[NSMutableArray alloc] init];
NSMutableArray *a2 = [NSMutableArray array];
TempObj *obj = [[TempObj alloc] init]; //assume this line is repeat
The basic thing to remember is this: You must balance every call to "init", "retain" or "copy" with a corresponding call to "release" or "autorelease". That's really all that you need to know.
In your example, a1 had a call to "init", so you need to have a "release" somewhere on it. Ditto with "obj". You didn't call "init", "retain", or "copy" on anything else, so you don't need to call "release" or "autorelease" on anything else.