Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

namanhams

macrumors regular
Original poster
Jun 3, 2009
153
0
I have googled around but i can not get the answer.

So i have 2 NSManagedObject class : A and B
A has a relationship with B, and B has an inverse relationship with A.
So in class A, the 'B' property is retain. And the same as in class B.

Code:
Class A :  
@property(nonatomic, retain) B *b;

class B :
@property(nonatomic, retain) A *a;

I have to do something like this in my code :
Code:
aObject.b = bObject;
bObject.a = aObject;

Then how can i release them ?
 

RonC

macrumors regular
Oct 18, 2007
108
0
Chicago-area
Have you tried something as simple as the inverse - like:
Code:
aObject.b = nil;
bObject.a = nil;
[aObject release];
[bObject release];

The @synthesized version of the property setter looks pretty much like:
Code:
-(void)getA:(ClassForA *)newA
{
    if (a) [a release];
    a = [newA retain];
}
so assigning nil results in a release to the retained object with nothing else getting retained (i.e., [nil retain]; doesn't really do anything).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.