开发者

How can I make sure nothing gets autoreleased?

I need a way to create variables that are accessible for the entire time my custo开发者_运维百科m class is initiated to when I call the release function. I need to retain a NSDate and a NSString.


Send the variable a retain message.


Do [myObject retain] or @property(nonatomic, retain) MyClass *myObject;


Autorelease just fires a -release message at a later time. If you want your variables to stick around, -retain them when they're assigned. Even if they're autoreleased, your retain will increment the retainCount, so they will not be dealloced. Just be sure to -release them in YOUR dealloc.


Give your custom class retain properties for each variable in its header file:

@property (nonatomic, retain) NSDate *myDate;
@property (nonatomic, retain) NSString *myString;

Be sure to create proper setters and getters, or use @synthesize, in its implementation file:

@synthesize myDate, myString;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜