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

chen8002004

macrumors newbie
Original poster
May 22, 2011
26
0
I would like to have a seperate class holding the data. Two objects can read and update the data. Is it possible to have one object own the data and the other object hold a pointer to the data? The other object will not retain the data class. Will this solution cause any possible memory leak?
 
Last edited:

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
A singleton might be overkill if you really just have the three objects.

You could have object A create and own object C, and then set an ivar in object B to equal the ivar in object A that points to object C. Just don't release object C from object B, unless you retain it there too.
 

chen8002004

macrumors newbie
Original poster
May 22, 2011
26
0
I did what xStep told me to. These is no error when running, but I get some warnings in Build: “No ‘assign’, ‘retain’, or ‘copy' attribute is specified - ‘assign’ is assumed” and “Assign attribute (default) not appropriate for non-gc object property ‘iC’ “. Can anyone help me with this warning?
Code:
@interface B: NSObject{
C* iC;
}
@property C* iC;
@end
 

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
Typically for your property statement you'd define at least whether it will perform a copy, a retain of the object id or simple accept an assignment of the id value. I'll leave it to you to learn more.

To remove the warnings, at minimum your code would look something like this;

Code:
@property (retain) C* iC;

or

Code:
@property (assign) C* iC;
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.