Re: Strange "exit due to Signal 11"
Re: Strange "exit due to Signal 11"
- Subject: Re: Strange "exit due to Signal 11"
- From: Michael Ströck <email@hidden>
- Date: Sat, 6 Aug 2005 16:53:12 +0200
Hi Haris,
Thank you for your reply. I figured out that I was doing many things
wrong soon after I wrote this message....
I'm still having problems with understanding memory management, so I
don't exactly know what you mean here:
tmpArray = [[myLines objectAtIndex:i]
componentsSeparatedByString:@";"];
You are now redirecting the pointer to point to the autoreleased
object that this method returns, hence in the process leaking the
newly constructed array in the previous line.
Can you explain?
What I have now looks like this, can you tell me wether it's more
acceptable?
<snip>
NSMutableArray * tmpArray = [[NSMutableArray alloc] init];
for(i=0;i<[myLines count];i++) {
[tmpArray setArray: [[myLines objectAtIndex:i]
componentsSeparatedByString:@";"] ];
if (tmpArray != nil) {
NSLog([tmpArray objectAtIndex:0]);
}
[tmpArray release];
</snip>
Thanks,
Michael Ströck
Am 06.08.2005 um 16:05 schrieb Charilaos Skiadas:
On Aug 6, 2005, at 8:49 AM, Michael Ströck wrote:
Hi,
I'm iterating over the lines I get from a CSV-file which has 5
columns.
This works fine:
This should not work quite fine, in fact I'm surprised it doesn't
crash. Let's go through it:
for(i=0;i<[myLines count];i++) {
NSArray * tmpArray = [[NSArray alloc] init];
You're creating a new array, which you are responsible for
NSLog([tmpArray objectAtIndex:0]);
Here you are assuming that tmpArray is not null, and I guess you
are being lucky
[tmpArray release];
Here you release the already autoreleased array, so if it gets
dealloced before the autorelease pool is flushed, you have a good
chance of crashing.
}
So instead, it should probably be something like:
NSArray * tmpArray = nil;
for(i=0;i<[myLines count];i++) {
tmpArray = [[myLines objectAtIndex:i]
componentsSeparatedByString:@";"];
if (tmpArray != nil) {
NSLog([tmpArray objectAtIndex:0]);
}
tmpArray = nil;
}
Anyway, moving on...
But the following dislpays the values and then (!?) exits with
"signal 11 (SIGSEGV)" :
for(i=0;i<[myLines count];i++) {
NSArray * tmpArray = [[NSArray alloc] init];
tmpArray = [[myLines objectAtIndex:i]
componentsSeparatedByString:@";"];
NSLog([tmpArray objectAtIndex:1]);
Are you making sure that tmpArray has more than one element? In
fact, are you making sure it has any elements at all? If not, then
you are trying to read beyond the bounds.
[tmpArray release];
}
The only difference is that I want to display the objectAtIndex:1
instead of atIndex:0 .
Why could that happen?
Thanks for any hints,
Michael
Haris
_______________________________________________
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