Objective-C Getter Memory Management -


I'm fairly new to Objective-C and I'm not sure how to correctly manage memory management in the following scenario. Behavior:

/ P>

I have a core data unit with a number of relationships for the "children" key as "Sir" as a child using an array To do this, I wrote the model class like this:

@interface AbstractItem: NSManagedObject {NSArray * arrangedChildren; } @protecti (nonatomic, raten) nset * children; @product (nanatomic, raten) nsnm * position; @protecti (nontamic, raten) nsarray * children arranged; @end @implementation AbstractItem @ dynamic children; @ Dynamic status; @Synthesis Systematic Children; - (NSARRA *) Children arranged [NSARRA * Irregular children = [[self. All children's objects are maintained); NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @ "status" ascending: yes]; [Systematic child release]; Arranged children = [un-organized child sorted by using the array Writer: [NSArray arrayWithObject: sortDescriptor]]; [Sortedipitre release]; [Unchanged child release]; Return [Maintaining a systematic child]; } @ And

I am not sure whether to maintain unmanaged children and returning children (the first and the last line of systematic children). Does the NSSet allObjects method already come back to a maintained array? Maybe it's too late and I have a lot of coffee.

If someone can tell me in the right direction then I will be truly grateful. I think I am remembering important parts of memory management knowledge and I will definitely see it as well.

all objects returns an autorel instance, maintaining it and releasing it There is no need to do

For the arranged child , only if you will use synthetic setter:

  Self. Organized child = [unplanned child sorted by userUser: /*...*/];  

By specifying the specified frequency as an example, you do not call a synthetic setter.

Finally, you should not have a return value here - your method isn ' alloc , new or form The name and the callers will have to do this in this way.

I recommend reading more section in Objective-language description.


Comments