I've been developing an app for about a week or so now and I thought it would be a good time to profile it to make sure I was doing everything correctly, what I found was that even though all my objects are getting dealloc'd the allocation amount is going up. When I release an object I do the following:
[object release];
object = nil;
In my app I have an initial view controller that determines to either show my LoginViewController
or TimeLineViewController
, depending on whether I have an access token. (This part doesn't matter as the problem I am having is within the LoginViewController
/SignupViewController
.). The login controller has two textfields and two buttons, these buttons either push the sVC onto the navigation view controller or attempt to login.
The weird thing is that the dealloc
methods are being called on my views and view controllers but the memory goes up after they are called.
SDK version 7.0 Xcode version 5.0
Edit:
In my LoginViewController this method is called when I get an event from the LoginView that the SignupButton has been clicked:
- (void)signupButtonPressed
{
SignupViewController *signupVC = [[SignupViewController alloc] init];
[self.navigationController pushViewController:signupVC animated:true];
destroy(signupVC);
}
***A note, the destroy macro is as follows:
#define destroy($x) \
if($x) \
{ \
[$x release]; \
$x = nil; \
}
When the SignupViewController is created the ViewDidLoad method is as follows:
self.view = [[SignupView alloc] initWithFrame:self.view.frame];
[[(SignupView *)self.view evtSignupButtonPressed] addHandler:AFFHandler(@selector(signupPressed))];
[((SignupView *)self.view).profileImage addTarget:self action:@selector(profileImagePressed) forControlEvents:UIControlEventTouchUpInside];
[self.navigationController setNavigationBarHidden:false animated:true];
It then creates the UI for the view inside SignupView which looks like this:
- (void)setupUI
{
self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:IS_IPHONE5 ? @"genericBackground-568h.jpg" : @"genericBackground.jpg"]];
_overlayView = [[UIView alloc] initWithFrame:self.frame];
_scrollView = [[UIScrollView alloc] initWithFrame:self.frame];
_profileImage = [[UIButton alloc] init];
profileImageContainer = [[UIView alloc] initWithFrame:CGRectMake(18.5, 0, _profileImage.imageView.image.size.width + 10, _profileImage.imageView.image.size.height + 10)];
selectProfilePictureText = [[UILabel alloc] initWithFrame:CGRectMake(profileImageContainer.affX, 0, 229, 17)];
UIView *padding = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 17, 40)];
_usernameField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 284, 40)];
_usernameField.delegate = self;
_passwordField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 284, 40)];
_passwordField.delegate = self;
_repeatPasswordField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 284, 40)];
_repeatPasswordField.delegate = self;
_emailField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 284, 40)];
_emailField.delegate = self;
destroy(padding);
buttonImage = [[UIImage imageNamed:@"largeButton.png"] copy];
_submitButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height)];
[_submitButton addTarget:self action:@selector(signupButtonPressed) forControlEvents:UIControlEventTouchUpInside];
destroy(buttonImage);
[self addSubview:_scrollView];
[self addSubview:_overlayView];
[_scrollView addSubview:profileImageContainer];
[profileImageContainer addSubview:_profileImage];
[_scrollView addSubview:selectProfilePictureText];
[_scrollView addSubview:_usernameField];
[_scrollView addSubview:_passwordField];
[_scrollView addSubview:_repeatPasswordField];
[_scrollView addSubview:_emailField];
[_scrollView addSubview:_submitButton];
destroy(profileImageContainer);
destroy(selectProfilePictureText);
}
**A note, Ive omitted all the code that changed properties of those objects like changing the backgroundColour and such.
The dealloc methods of the SignupVC and the SignupView are as follows:
SignupView:
- (void)dealloc
{
self.usernameField.delegate = nil;
self.passwordField.delegate = nil;
self.repeatPasswordField.delegate = nil;
self.emailField.delegate = nil;
AFFRemoveAllEvents();
destroyAndRemove(_usernameField);
destroyAndRemove(_passwordField);
destroyAndRemove(_repeatPasswordField);
destroyAndRemove(_emailField);
destroyAndRemove(_profileImage);
destroyAndRemove(_submitButton);
destroyAndRemove(_scrollView);
destroyAndRemove(_overlayView);
if(buttonImage)
destroy(buttonImage);
[super dealloc];
}
SignupVC (this gets called after the backbutton of the NavigationBar is pressed)
- (void)dealloc
{
[[(SignupView *)self.view evtSignupButtonPressed] removeHandlersForObserver:self];
[((SignupView *)self.view).profileImage removeTarget:self action:@selector(profileImagePressed) forControlEvents:UIControlEventTouchUpInside];
destroy(profileImage);
destroyAndRemove(self.view);
[super dealloc];
}
DestroyAndRemove does this:
#define destroyAndRemove($x) \
if($x) \
{ \
[$x removeFromSuperview]; \
[$x release]; \
$x = nil; \
}