newbie: question: i have a memory leak: obj-c 2.0: modification of program in "Cocoa with Objective-C"
newbie: question: i have a memory leak: obj-c 2.0: modification of program in "Cocoa with Objective-C"
- Subject: newbie: question: i have a memory leak: obj-c 2.0: modification of program in "Cocoa with Objective-C"
- From: George Greene <email@hidden>
- Date: Sun, 3 Feb 2008 15:45:23 -0500
the code i am using is a modification of the code/problem found in
"Cocoa with Objective-C", chapter 3.
i have tried to use the objective-c 2.0 garbage collector
methodology, using @property, @synthesize, etc. when i run the code
as listed below i get a leaking message.
[Session started at 2008-02-01 23:33:37 -0500.]
2008-02-01 23:33:38.070 SongsFoundationTool[28876:10b] ***
_NSAutoreleaseNoPool(): Object 0x2040 of class NSCFString
autoreleased with no pool in place - just leaking
Stack: (0x96b10178 0x96a3e0f8)
2008-02-01 23:33:38.075 SongsFoundationTool[28876:10b] Song 1: We
Have Exposive
2008-02-01 23:33:38.076 SongsFoundationTool[28876:10b] ***
_NSAutoreleaseNoPool(): Object 0x2060 of class NSCFString
autoreleased with no pool in place - just leaking
Stack: (0x96b10178 0x96a3e0f8)
2008-02-01 23:33:38.078 SongsFoundationTool[28876:10b] Song 2: Loops
of Fury
The Debugger has exited with status 0.
when i include the commented out section, in the implementation file
section, the description method, and use song1 and song2, in main,
instead of song1.name and song2.name the program seems to run fine.
The Debugger has exited with status 0.
[Session started at 2008-02-01 23:38:24 -0500.]
2008-02-01 23:38:24.375 SongsFoundationTool[28936:10b] Song 1: We
Have Exposive
2008-02-01 23:38:24.379 SongsFoundationTool[28936:10b] Song 2: Loops
of Fury
The Debugger has exited with status 0.
please help me understand what's happening here.
also, why was it necessary to use
@property(copy, readwrite) NSString *name;
@property(copy, readwrite) NSString *artist;
instead of
@property(readwrite) NSString *name;
@property(readwrite) NSString *artist;
thanks everyone, the code is below.
// ....................... header file ...............
#import <Cocoa/Cocoa.h>
@interface Song : NSObject {
NSString *name;
NSString *artist;
}
@property(copy, readwrite) NSString *name;
@property(copy, readwrite) NSString *artist;
@end
//.................... the implementation file ..................
#import "Song.h"
@implementation Song
@synthesize name;
@synthesize artist;
/*
-(NSString *) description
{
return [ self name ];
}
*/
@end
//................................ main............................
#import <Foundation/Foundation.h>
#import "Song.h"
int main (int argc, const char * argv[]) {
Song *song1 = [ [ Song alloc ] init ];
song1.name= @"We Have Exposive" ;
[ song1 setArtist: @"The Future Sound Of Londown" ];
Song *song2 = [ [ Song alloc ] init ];
[ song2 setName: @"Loops of Fury" ];
[ song2 setArtist: @"The Chemical Brothers" ];
// Display Object
NSLog( @"Song 1: %@", song1.name );
NSLog( @"Song 2: %@", song2.name );
return 0;
}
_______________________________________________
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