This is the code, it doesn’t work when [unosUpisa release]; and [unosRazlike release]; are entered;
How to properly release those unosUpisa and unosRazlike objects?
-(IBAction) padIliStilja: (id) sender
{
NSNumber *unosUpisa = [[NSNumber alloc] init];
NSNumber *unosRazlike = [[NSNumber alloc] init];
if ([sender tag] == 1)
{
unosUpisa = [NSNumber numberWithInt: 162 + [Data variables].zvanja];
unosRazlike = [NSNumber numberWithInt: 0];
}
else if ([sender tag] == 2)
{
unosRazlike = [NSNumber numberWithInt: 252 + [Data variables].zvanja];
unosUpisa = [NSNumber numberWithInt: 0];
}
if ([Data variables].upisZaMi == NO)
{
[[Data variables].rezultatMi addObject: unosUpisa];
[[Data variables].rezultatVi addObject: unosRazlike];
}
else
{
[[Data variables].rezultatVi addObject: unosUpisa];
[[Data variables].rezultatMi addObject: unosRazlike];
}
[self dismissModalViewControllerAnimated: NO];
[unosUpisa release];
[unosRazlike release];
}
You have to
releaseevery object that you own (you retained, copied, or init/alloced).The way you release your objects at the end is correct, but, here
unosRazlike = [NSNumber numberWithInt: 0];, you assignedunosRazlikeanother value, without releasing the previous one, and here is a leak.Also, with this kind of method, you should retain your object.
So :
EDIT
But just a thought… why initializing ‘blank’ number objects, if you set the value either in the if or in the else part ?
Just declare them
and set their values in the if/else.