My app gives a low memory crash on the device and not on the simulator.I used Instruments and i think that the problem lies in the following part
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"gembtnblu.png"] forState:UIControlStateNormal];<br>
button.frame = CGRectMake(0, 0, TOOLBAR_BUTTON_WIDTH , TOOLBAR_BUTTON_HEIGHT);<br>
[button setTitle:[NSString stringWithFormat:@"%c",choice] forState:UIControlStateNormal];<br>
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(ChoiceButtonTouched:) forControlEvents:UIControlEventTouchUpInside];
[button setTag:choice];
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
//Add button to the array
[tempItems addObject:customBarItem];
if (isReviewing == TRUE) {
customBarItem.customView.userInteractionEnabled=FALSE;
}
//release buttons
[customBarItem release];
numberOfChoices++;
But im not able to spot the problem.Please help guuys, i have beeen stuck at this for days now
heres some more code
NSArray *items=[[NSArray alloc] initWithArray:(NSArray *)tempItems];
[tempItems release];
//add array of buttons to toolbar
[toolbar setItems:items animated:YES];
[self.view addSubview:toolbar];
the static analyser says that theres a potential leak with ‘items’ array.But if i put in a release statement, the app crashes
Did you release the toolbar after adding it as a subview? If you did not, and are not releasing the toolbar in the dealloc, there’s your leak.