Re: Using methods that retain..
Re: Using methods that retain..
- Subject: Re: Using methods that retain..
- From: Henry McGilton <email@hidden>
- Date: Sat, 16 Aug 2003 09:10:38 -0700
On Saturday, August 16, 2003, at 08:29 AM, Michael Hanna wrote:
After making many adjustments in order that my lines object is
retained, I still am having sig10 problems..
Down at the end of your code samples, you have the following lines of
code:
- (NSArray *)tokenLines
{
NSLog(@"[acc. meth.]tokenLines retainCount: %@", [tokenLines
retainCount]);
return tokenLines;
}
The %@ format code looks bogus to me. [tokenLines retainCount]
returns an integer, whereas
%@ designates an object reference. Try using %d instead.
my CSController creates the object, and I'm pretty certain it's
retained properly but the sig10 results when trying to access it:
I create it when I awakeFromNib:
- (void)awakeFromNib
{
[copyToClipboardButton setEnabled:NO];
phrases = [[Phrases alloc] init];
lines = [[Lines alloc] init];
}
when the user clicks the generate button: it's sent this message:
- (IBAction)generate:(id)sender
{
unsigned i; // an index value for the for-loop, increments
through lineArray
unsigned phraseNum = 0; // a value that increments through the 12
phrases in phraseArray
NSMutableArray *lineArray;
NSArray *phraseArray;
NSMutableString *theLine;
NSString *tokString;
NSString *mySongString;
NSLog(@"got here 1");
lineArray = [[NSMutableArray alloc] initWithArray:[lines
tokenLines]];
NSLog(@"got here 1.25");
//[lineArray initWithArray:[lines tokenLines]];
NSLog(@"got here 1.5");
NSLog(@"lineArray: %@", lineArray);
tokString = [[NSString alloc] initWithString:[lines token]];
NSLog(@"got here 2");
[...]
in CSController.h, I declare lines as such:
@interface CSController : NSObject
{
IBOutlet NSImageView *theImageView;
IBOutlet NSTextField *theTextView;
IBOutlet NSButton *copyToClipboardButton;
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication
*)sender;
- (IBAction)copyToClipboard:(id)sender;
- (IBAction)generate:(id)sender;
unsigned randPhrase(int length);
Phrases *phrases;
Lines *lines;
[....]
In Lines.m, my init method is such:
- (id)init
{
NSLog(@"got here lines 1");
self = [super init];
NSLog(@"got here lines 2");
linesPath = [[NSBundle mainBundle] pathForResource:@"lines"
ofType:@"plist"];
NSLog(@"got here lines 3");
lineDict = [NSDictionary dictionaryWithContentsOfFile: linesPath];
NSLog(@"got here lines 4");
key = @"lines"; // key to get lineArray from the NSDictionary
NSLog(@"got here lines 5");
tokenString = @"%s"; // the 12 tokens to be replaced within the
while-loop
NSLog(@"got here lines 6");
tokenLines = [[NSArray alloc] initWithArray:[lineDict
objectForKey:key]];
NSLog(@"got here lines 7");
return self;
}
[...]
and my accessor looks like:
- (NSArray *)tokenLines
{
NSLog(@"[acc. meth.]tokenLines retainCount: %@", [tokenLines
retainCount]);
return tokenLines;
}
Output
my output is like this:
2003-08-16 11:17:24.578 Country Song[2850] got here lines 1
2003-08-16 11:17:24.580 Country Song[2850] got here lines 2
2003-08-16 11:17:24.581 Country Song[2850] got here lines 3
2003-08-16 11:17:24.593 Country Song[2850] got here lines 4
2003-08-16 11:17:24.596 Country Song[2850] got here lines 5
2003-08-16 11:17:24.597 Country Song[2850] got here lines 6
2003-08-16 11:17:24.597 Country Song[2850] got here lines 7
2003-08-16 11:17:28.095 Country Song[2850] got here 1
Country Song has exited due to signal 10 (SIGBUS).
so I'm pretty sure my program crashes on this line in CSController.m:
lineArray = [[NSMutableArray alloc] initWithArray:[lines
tokenLines]];
clearly it's not being retained, but doesn't this line in the init of
Lines.m retain it? :
tokenLines = [[NSArray alloc] initWithArray:[lineDict
objectForKey:key]];
I'm still not clear why I'm getting a sig10..
please excuse my newbieness,
Michael
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden |
http://www.trilithon.com
|
===============================+============================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.