Reputation: 9716
Hi so I have a popoverviewcontroller with a tableview in it. everytime i press the button to view the popover, some memory is allocated (1024). If i press it multiple times the allocations just grows and grows. Since the app is written in ARC i thought this would be handled by the automatic. How do i make sure that my popover does infact remove all allocated data when removed, code is attached below:
//
// SettingPopOverViewController.m
// CodeFriend
//
// Created by Exjobb on 5/22/13.
// Copyright (c) 2013 davidkarlsson. All rights reserved.
//
#import "ThemesPopOverViewController.h"
@interface ThemesPopOverViewController ()
@end
@implementation ThemesPopOverViewController
@synthesize tableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
themes = [[NSArray alloc] initWithObjects:kRegexHighlightViewThemeArray];
self.tableView = nil;
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(20, 0, self.view.frame.size.width - 40, 350)];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
[self.view addSubview:self.tableView];
int item = [themes indexOfObject:theDelegate.codeView.currentTheme];
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:0];
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; //count of section
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//NSLog(@"%d",themes.count);
return [themes count]; //count number of row from counting array hear cataGorry is An Array
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier];
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor colorWithRed:25/255.0f green:185/255.0f blue:152/255.0f alpha:1.0f]];
[cell setSelectedBackgroundView:bgColorView];
}
[cell.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
cell.textLabel.text = [themes objectAtIndex: indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"%d", indexPath.row);
[theDelegate.codeView setHighlightThemeFromString:[themes objectAtIndex:indexPath.row]];
[theDelegate removePop];
}
@end
I am showing the pop with:
-(void) settingAct:(UIButton *)sender{
if (!popover) {
ThemesPopOverViewController *newView = [[ThemesPopOverViewController alloc] initWithNibName:@"SettingPopOverViewController" bundle:[NSBundle mainBundle]];
self.popover = [[WEPopoverController alloc] initWithContentViewController:newView];
[self.popover setContainerViewProperties:[self improvedContainerViewProperties]];
[self.popover setPopoverContentSize:CGSizeMake(128, 360)];
[self.popover presentPopoverFromRect:CGRectMake(sender.center.x+12, sender.center.y, 0, 20)
inView:self.window.rootViewController.view
permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown|
UIPopoverArrowDirectionLeft|UIPopoverArrowDirectionRight)
animated:YES];
}else{
[self removePop];
}
}
The popover is removed using just:
-(void) removePop{
[self.popover dismissPopoverAnimated:YES];
self.popover = nil;
}
Upvotes: 0
Views: 147
Reputation: 41682
WePopOver if I recall is not ARCified. There is an Arc version at this link. I don't know for sure but that may be the issue. The other thing you can do is add a log message in all relevant object subclasses, in the dealloc method, so you can observe when the popover is dismissed which objects are NOT released.
Upvotes: 1