• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Memory Allocation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Memory Allocation
      • From: "Kyle Sluder" <email@hidden>
  • Prev by Date: Re: Handling key equivalents in a controller class?
  • Next by Date: Re: UITextView for the iphone that will auto-detect URLs
  • Previous by thread: Re: UITextView for the iphone that will auto-detect URLs
  • Next by thread: Re: Memory Allocation
  • Index(es):
    • Date
    • Thread