• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Should I release an array created with componentsSeparatedByString?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Should I release an array created with componentsSeparatedByString? (From: Tony Gray <email@hidden>)

  • Prev by Date: Should I release an array created with componentsSeparatedByString?
  • Next by Date: Re: NSString Unicode canonical decompositions?
  • Previous by thread: Should I release an array created with componentsSeparatedByString?
  • Next by thread: Re: NSString Unicode canonical decompositions?
  • Index(es):
    • Date
    • Thread