Should I release an array created with componentsSeparatedByString?
Should I release an array created with componentsSeparatedByString?
- Subject: Should I release an array created with componentsSeparatedByString?
- From: Tony Gray <email@hidden>
- Date: Mon, 01 Apr 2002 17:23:32 +1000
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.