Re: NSMutableString question

2008-09-17 Thread Jason Coco
On Sep 17, 2008, at 12:08 , Roland King wrote: You'd think perhaps that alloc/init would give you an object which really has never been retained by anyone else, but as I said I remembered a post from a while ago about a complex object which was alloc/init'ed but ended up still having a reta

Re: NSMutableString question

2008-09-17 Thread Roland King
plicated, however once you learn to "play by the rules", it makes good sense. Enjoy, Matt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Bill Bumgarner Sent: Tuesday, September 16, 2008 10:50 PM To: Roland King Cc: Cocoa Developers Subjec

RE: NSMutableString question

2008-09-17 Thread Matthew Youney
ubject: Re: NSMutableString question On Sep 16, 2008, at 7:41 PM, Roland King wrote: > Jason Coco wrote: > >> >> NSMutableString *str = [[NSMutableString alloc] Â >> initWithCapacity:someAssumedCapacity]; >> /* do stuff */ >> [str release]; >> > Is that actually

Re: NSMutableString question

2008-09-16 Thread Jason Coco
On Sep 16, 2008, at 22:41 , Roland King wrote: Jason Coco wrote: NSMutableString *str = [[NSMutableString alloc] initWithCapacity:someAssumedCapacity]; /* do stuff */ [str release]; Is that actually guaranteed to release the string *right now*? I only ask because I seem to recall a me

Re: NSMutableString question

2008-09-16 Thread Graham Cox
On 17 Sep 2008, at 12:41 pm, Roland King wrote: Is that actually guaranteed to release the string *right now*? I only ask because I seem to recall a message a couple of months ago about a more complicated object where it appeared that the initializer did a retain/autorelease on the object

Re: NSMutableString question

2008-09-16 Thread Bill Bumgarner
On Sep 16, 2008, at 7:41 PM, Roland King wrote: Jason Coco wrote: NSMutableString *str = [[NSMutableString alloc] Â initWithCapacity:someAssumedCapacity]; /* do stuff */ [str release]; Is that actually guaranteed to release the string *right now*? I only ask because I seem to recall a me

Re: NSMutableString question

2008-09-16 Thread Roland King
Jason Coco wrote: NSMutableString *str = [[NSMutableString alloc] initWithCapacity:someAssumedCapacity]; /* do stuff */ [str release]; Is that actually guaranteed to release the string *right now*? I only ask because I seem to recall a message a couple of months ago about a more complicat

Re: NSMutableString question

2008-09-16 Thread Jason Coco
On Sep 16, 2008, at 21:58 , Bill Bumgarner wrote: On Sep 16, 2008, at 6:29 PM, Jason Coco wrote: Is it actually retained by the pool, or does the pool just delay the final release? It doesn't really matter how it's implemented... either way, you shouldn't release it unless you own it (i.e.

Re: NSMutableString question

2008-09-16 Thread Bill Bumgarner
On Sep 16, 2008, at 6:29 PM, Jason Coco wrote: Is it actually retained by the pool, or does the pool just delay the final release? It doesn't really matter how it's implemented... either way, you shouldn't release it unless you own it (i.e., you've retained it yourself or gotten it from on

Re: NSMutableString question

2008-09-16 Thread Jason Coco
On Sep 16, 2008, at 21:24 , Dave DeLong wrote: On 16 Sep, 2008, at 7:22 PM, Graham Cox wrote: On 17 Sep 2008, at 11:11 am, Dave DeLong wrote: because only a couple days ago I had a crash when I tried releasing an already autoreleased object Yes, because that would be an over-release.

Re: NSMutableString question

2008-09-16 Thread Dave DeLong
On 16 Sep, 2008, at 7:22 PM, Graham Cox wrote: On 17 Sep 2008, at 11:11 am, Dave DeLong wrote: because only a couple days ago I had a crash when I tried releasing an already autoreleased object Yes, because that would be an over-release. release must be balanced by a preceding retain.

Re: NSMutableString question

2008-09-16 Thread Graham Cox
On 17 Sep 2008, at 11:11 am, Dave DeLong wrote: because only a couple days ago I had a crash when I tried releasing an already autoreleased object Yes, because that would be an over-release. release must be balanced by a preceding retain. But once an object has been added to an autorele

Re: NSMutableString question

2008-09-16 Thread Dave DeLong
Earlier today I was experimenting with NSAutoreleasePools and built a little demo app. Basically it was two nested loops (the outer having 100 iterations, the inner 1000), and on each iteration of the inner loop, I created an autoreleased string (using stringWithFormat:). I ran it twice.

Re: NSMutableString question

2008-09-16 Thread Ken Thomases
On Sep 16, 2008, at 7:59 PM, Dave DeLong wrote: The general rule with convenience class methods like that is that they return an autoreleased object. They return an object for which you do not have responsibility to release. It may or may not be technically autoreleased. What that means

Re: NSMutableString question

2008-09-16 Thread Dave DeLong
Thanks for the heads up. I think if I had thought about that a little longer I probably wouldn't have written it, because only a couple days ago I had a crash when I tried releasing an already autoreleased object. Whoops. =) Dave On 16 Sep, 2008, at 7:07 PM, Graham Cox wrote: On 17 S

Re: NSMutableString question

2008-09-16 Thread Jim Correia
On Sep 16, 2008, at 8:59 PM, Dave DeLong wrote: The general rule with convenience class methods like that is that they return an autoreleased object. The rules are encapsulated in the object ownership policy:

Re: NSMutableString question

2008-09-16 Thread Jason Coco
On Sep 16, 2008, at 20:59 , Dave DeLong wrote: The general rule with convenience class methods like that is that they return an autoreleased object. What that means is that unless you retain it, it will disappear at some time in the future (whenever the current AutoreleasePool gets draine

Re: NSMutableString question

2008-09-16 Thread Graham Cox
On 17 Sep 2008, at 10:59 am, Dave DeLong wrote: NSString * str = [NSMutableString string]; //do stuff with str [[str retain] release]; HOWEVER, that might cause funky things to happen with the autorelease pool. So the best idea is to do nothing and let the autorelease pool take care of it

Re: NSMutableString question

2008-09-16 Thread Dave DeLong
The general rule with convenience class methods like that is that they return an autoreleased object. What that means is that unless you retain it, it will disappear at some time in the future (whenever the current AutoreleasePool gets drained). So if you want to "reclaim" the space, you d

NSMutableString question

2008-09-16 Thread John Zorko
Hello, all ... I've another simple ObjC question that I hope someone can answer -- this has to do with memory management and NSMutableString. If I do this: NSString *str = [NSMutableString string]; ... what is the best way to reclaim that space? Do I do [str release] (no alloc was c