Re: Should I release an array created with componentsSeparatedByString?
Re: Should I release an array created with componentsSeparatedByString?
- Subject: Re: Should I release an array created with componentsSeparatedByString?
- From: Raphael Sebbe <email@hidden>
- Date: Mon, 1 Apr 2002 09:40:01 +0200
Hi,
There is a note somewhere in the doc stating object ownership. Or just
check the archive, it is there !
[theLongString componentsSeparatedByString:@"\n"];
The returned array is autoreleased, you should not release it (unless
you explicitly retain it). That explains the crash and does not solve
your leak problem.
Raphael
On Monday, April 1, 2002, at 09:23 AM, Tony Gray wrote:
>
I'm trying to trace a memory leak in my application. Here's a snippet
>
of
>
the code:
>
>
NSArray *separatedStrings;
>
separatedStrings = [theLongString
>
componentsSeparatedByString:@"\n"];
>
>
The function this is in gets called every 2 seconds, and theLongString
>
contains 8 lines of data which I'm breaking into separate strings in the
>
array. I thought this was the source of the memory leak, since the
>
separatedStrings array wasn't getting released or autoreleased.
>
>
So I modified the code so that at the end of the function I do:
>
>
[separatedStrings release];
>
>
With this in place, I usually get a crash within 10 seconds (but the
>
exact
>
timing varies). I also get a crash when I move the mouse outside the
>
application window (although I'm not monitoring the mouse for this, and
>
so I
>
suspect an autorelease issue). Am I supposed to release/autorelease the
>
separatedStrings array myself at the end of the function that creates
>
it?
>
None of the sample code I've seen does this.
>
>
By the way, after separating the strings, I'm stuffing their values in
>
some
>
UI objects like this:
>
>
[someOutlet setStringValue:[separatedStrings objectAtIndex:i]];
>
>
I assumed that Cocoa would copy my strings for its own private use, but
>
maybe I am assuming wrong. Is it using the strings that I'm releasing,
>
hence the crash?
>
_______________________________________________
>
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.
_______________________________________________
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.