Re: some crash i can not explain.
Re: some crash i can not explain.
- Subject: Re: some crash i can not explain.
- From: Sandro Noel <email@hidden>
- Date: Mon, 23 Oct 2006 15:43:08 -0400
Glenn, Thank you for the insight and the sample code!
alloc resolved my problem.
but i still do not understand "why" the array was released before i
had a chance to use it... i tought that since it was an instance
variable it was "owned" by the instance
and that a "retain" was not needed whatever i created the object with...
oh well, more reading to do :P
Andrew, thank you for the reference, I had read it, but i must have
missed something.
will do my homework again :)
Thank you much for the assistance! it is appreciated!
Sandro Noel.
On 23-Oct-06, at 3:24 PM, Glenn Zelniker wrote:
On Oct 23, 2006, at 3:10 PM, Sandro Noel wrote:
First off, thank you Nick.
I corrected every location where i had made the mistake,
but i still get the runtime error, in this block of code.
-(int)addName:(NSString *)name{
ADTreeViewItem *item = [[ADTreeViewItem alloc]init];
[item setDisplayString:name];
[arrayofNames addObject:item];
return [arrayOfNames count];
}
I was thinking that the "item" variable was not in a good place,
and was released after the function ended,and that might cause
problems but then i red up on Array's and they retain objects, so
it should not matter where the object is allocated from.
[arrayofNames addObject:item];
this somehow crashes the app without an error message in the NSLog.
I think you might also be having trouble with the line
arrayOfNames = [[NSMutableArray array] init];
The way you've done it, the array won't be retained because -array
is a convenience method and will return an autoreleased object. You
could use
arrayOfNames = [[NSMutableArray array] retain];
or
arrayOfNames = [[NSMutableArray alloc] init];
instead. For the latter, you won't need a -retain message because
arrayOfNames is an instance variable in your class.
HTH,
Glenn Zelniker
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden