Re: Understanding ARC

2014-06-03 Thread Dave
Hi, The only time you need to worry about autoreleased objects (if your App is 100% ARC), is when you call third party (including Apple) APIs. Even then it shouldn’t really cause a problem unless you are running in a loop which doesn’t call the run loop. In this case, depending on the APIs you

Re: Understanding ARC

2014-05-27 Thread Jamie Ojomoh
> YOU ARE OVERTHINKING THIS. Stop trying to figure out when things are getting released — that’s ARC’s job. Just write your code. That's what my dad said, but I though he just didn't know what the real answer was. Thank you for your helps. On Sun, May 25, 2014 at 5:46 PM, Jens Alfke wrote: >

Re: Understanding ARC

2014-05-25 Thread Charles Srstka
On May 25, 2014, at 11:38 AM, Jens Alfke wrote: > On May 24, 2014, at 11:34 PM, Charles Srstka wrote: > >> This isn't strictly true; when you are returning objects by reference, doing >> so inside the @autoreleasepool will cause a crash. For example: > > That’s a different scenario than the o

Re: Understanding ARC

2014-05-25 Thread Jens Alfke
On May 25, 2014, at 2:07 AM, Jamie Ojomoh wrote: > So if I use alloc/init then autoreleasepool doesn't work? No, I meant that the string hasn’t been autoreleased at all yet, so the pool isn’t going to release it when it exits. The pool “works”, it’s just not necessary. > Or don't I need auto

Re: Understanding ARC

2014-05-25 Thread Jens Alfke
On May 24, 2014, at 11:34 PM, Charles Srstka wrote: > This isn't strictly true; when you are returning objects by reference, doing > so inside the @autoreleasepool will cause a crash. For example: That’s a different scenario than the one the OP was asking about; stuffing a reference into the

Re: Understanding ARC

2014-05-25 Thread Jamie Ojomoh
Thank you for all your helps. >>You allocated returnString using an alloc/init sequence so it’s not in an autorelease pool at all. So if I use alloc/init then autoreleasepool doesn't work? If thats so, how do I use NSMutableString? I can use NSString without alloc/init, but Mutable always requi

Re: Understanding ARC

2014-05-24 Thread Charles Srstka
On May 24, 2014, at 5:04 PM, Jens Alfke wrote: > On May 24, 2014, at 2:34 PM, Jamie Ojomoh wrote: > >> In the example, everything inside the autoreleasepool block will be >> released as soon as the block ends, so it's necessary to declare the return >> value outside the block. > > No, in gener

Re: Understanding ARC

2014-05-24 Thread Jens Alfke
On May 24, 2014, at 2:34 PM, Jamie Ojomoh wrote: > In the example, everything inside the autoreleasepool block will be > released as soon as the block ends, so it's necessary to declare the return > value outside the block. No, in general ARC understands that the return value needs to keep a re

Re: Understanding ARC

2014-05-24 Thread Jim Geist
The compiler handles the case of a returned object properly. Ownership in the form of one reference will pass, in your example, from returnString to testString due to the assignment to the return value. testString will be released when the block it’s in exits, and since there are no more referre

Understanding ARC

2014-05-24 Thread Jamie Ojomoh
Dear Sir, I'm trying to teach myself Objective C and I don't understand ARC very well. Please could someone help me. If I've understood this correctly (silly example): -(NSString*)stringdoodad { NSMutableString* returnString = [[NSMutableString alloc] init]; @autoreleasepool {