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 Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-27-2009, 04:54 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 171
Question Instruments 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-28-2009, 06:33 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 3
Default

Hi,

So the memory size continues to rise for as long as you keep the application running? If I had to hazard a guess without seeing your "Do stuff here" code I'd say it's probably the autorelease on the calendar object. Autorelease can be a bit tricky, IIRC it'll hold onto a reference to those objects until it returns to the application's main run loop (basically where it sits waiting for events). Normally that works fine, I know in threads it can get a bit more complicated and I think NSTimer basically launches a new thread for each time it fires so that may be preventing the normal autorelease behaviour.

I'd recommend avoiding autorelease whenever possible, fortunately there's no need to use it here. You could either:
  • Create the calendar object once during viewDidLoad, reuse it throughout the view's lifetime and then release during viewDidUnload
  • Create at the start of updateL (as you are at the moment, but without the autorelase), and then release just before the end of the method.

I'm guessing the same probably goes for the parts of your "Do stuff here" code where you create the strings. I suggest you manually release objects whenever you can, at least that way you can be clear exactly when it's happening.

James
jmccalden 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
» Online Users: 249
18 members and 231 guests
ADY, Alsahir, beleg_1998, Dani77, e2applets, iph_s, JamesCahall, JasonR, mer10, Monstertaco, prchn4christ, Promo Dispenser, Robiwan, Rudy, smithdale87, timle8n1, Touchmint
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,756
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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