Memory Allocation
Memory Allocation
- Subject: Memory Allocation
- From: "Alexandre Badez" <email@hidden>
- Date: Wed, 16 Jul 2008 20:02:10 +0200
Hy,
I'm an early beginner in Objectiv-C and Cocoa, and for learning I'm
actualy reading "Cocoa Programming for Mac OS X" (Third Edition).
In chapter 5, I've made the challenge (a dialog box that count the
lenght of the text field and display the result).
For curiosity purpose, I launched my app with the "object allocations"
tool (Run -> Start with Performance tools -> Object Allocations). When
my app is running, I press many time on the button for counting the
lengh of the string. And here, in the allocation tool, I can see that
the overall process is increasing in memory (I think).
So I must have omit some "release" method I suppose; but I can't see where.
Here is my source code:
##### AppController.h #####
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject {
IBOutlet NSTextField *inTextField;
IBOutlet NSTextField *outTextField;
}
-(IBAction) countChar: (id)sender;
-(void) setOutString: (NSString*)outString;
@end
##### AppController.m ######
#import "AppController.h"
@implementation AppController
-(id)init
{
if (![super init])
return nil;
NSLog(@"init %@", [self className]);
return self;
}
-(IBAction)countChar:(id)sender
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *userString;
NSLog(@"Counting char");
userString = [inTextField stringValue];
[self setOutString:
[NSString stringWithFormat: @"'%@' lenght: %d",
userString,
[userString length]]];
[pool drain];
}
-(void) setOutString: (NSString *) outString
{
NSLog(@"Set textfiled with: '%@'", outString);
[outTextField setStringValue: outString];
}
@end
###### END #######
If you need, I can send you the project
Thanks.
--
Alex
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden