【发布时间】:2009-05-03 22:21:17
【问题描述】:
我仍在学习 Objective-C 内存管理。我正在尝试在我正在构建的示例程序中实现几个简单的类。
例如,假设我有以下类定义:
#import <UIKit/UIKit.h>
@interface customViewController : UIViewController
{
customObject *myCustomObject;
}
@property (retain) customObject *myCustomObject;
- (void)replaceCustomObject:(customObject *)newObject;
@end
对于属性,我使用标准的 synthesize 关键字...
@synthesize myCustomObject;
那么请假设在 customViewController 的实例中 myCustomObject 已经设置了一个有效值并且正在使用中。那么replaceCustomObject方法定义为:
- (void)replaceCustomObject:(customObject *)newObject
{
//Does this cause a memory leak because I just assign over
//the existing property?
self.myCustomObject = newObject;
}
正如评论所问,这会泄漏内存吗? 或者这是用新对象替换先前对象的有效方法?
谢谢你,
弗兰克
【问题讨论】:
标签: objective-c iphone memory-management