Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tools & Utilities

Reply
 
LinkBack Thread Tools Display Modes
Old 11-27-2009, 05:46 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 171
Question Instruments / Memory Question

I have recently completed my first for fun app in xcode (using 3.1.2). The application is a countdown to my birthday and everything seems to work. I have tried running the app in Instruments to make sure there is no leaks or anything else wrong with it.

Running the app in Instruments shows me there are no leaks in the app, however, when looking at ObjectAlloc, I am a little confused on what is going on. When the app launches, Net Bytes, # Net and Overall Bytes continue to rise. It might be that I am not releasing certain things that I should, but I am not sure what I am doing wrong.

Here is the code for the project. Can anyone please help me?

AppDelegate.h

#import <UIKit/UIKit.h>
@class _010ViewController;

@interface _010AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
_010ViewController *viewController;
NSTimer *timer;
}

-(void)goTime;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet _010ViewController *viewController;
@end

AppDelegate.m
#import "_010AppDelegate.h"
#import "_010ViewController.h"
@implementation _010AppDelegate
@synthesize window;
@synthesize viewController;

- (void)applicationDidFinishLaunchingUIApplication *)application {
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

timer = [NSTimer scheduledTimerWithTimeInterval1.0) target:self
selector:@selector(goTime) userInfo:nil repeats:YES];

[window addSubview:viewController.view];
[window makeKeyAndVisible];
}

- (void)goTime {
[viewController updateL];
}

- (void)dealloc {
[timer release];
[viewController release];
[window release];
[super dealloc];
}
@end

ViewContrller.m
#import "_010ViewController.h"
@implementation _010ViewController

- (void)viewDidLoad {
//sets up the fond and the labels for the text to be displayed
[counterL setFont:[UIFont fontWithName:@"Zapfino" size:20]];
[counterB setFont:[UIFont fontWithName:@"Zapfino" size:20]];
counterL.textColor = [UIColor whiteColor];
counterB.textColor = [UIColor whiteColor];
counterL.text = @"D";
counterB.text = @"A";
[super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

- (void)dealloc {
[counterL release];
[counterB release];
[super dealloc];
}

- (void)updateL {
NSCalendar *calendar= [[[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar] autorelease];

NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit
| NSDayCalendarUnit | NSHourCalendarUnit |
NSMinuteCalendarUnit | NSSecondCalendarUnit;

NSDate *date = [NSDate date];

NSDateComponents *dateComponents = [calendar
components:unitFlags fromDate:date];

int year = [dateComponents year];
int month = [dateComponents month];
int day = [dateComponents day];
int hour = [dateComponents hour];
int minute = [dateComponents minute];
int second = [dateComponents second];

/* Do Stuff here with those ints to calculate the time remaining and
change the labels based on them
@end

ViewController.h
#import <UIKit/UIKit.h>

@interface _010ViewController : UIViewController {
IBOutlet UILabel *counterL;
IBOutlet UILabel *counterB;
}

-(void)updateL;

@end
dalson is offline   Reply With Quote
Old 11-27-2009, 06:38 PM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: London
Posts: 226
Default

Nope. That all looks perfectly fine and leak-free.

(The only thing I'd say is that in the app delegate's dealloc you should call [timer invalidate] rather than [timer release]. The timer you've created is autoreleased and only retained by its run-loop, rather than by you. If you did this anywhere else it would be a problem, but since it's in the app delegate dealloc which is only called as the app is exiting it really isn't a problem.)

Maybe you could post the rest of the -updateL method.
__________________
SimCap - Simple iPhone and iPad Simulator screen capture
_sjc_ is offline   Reply With Quote
Reply

Bookmarks

Tags
alloc, instruments, memory

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:17 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0