내가 뭘 잘못하고 있는지 파악하기가 힘듭니다. 누군가가 올바른 방향으로 나를 가리킬 수 있기를 바랍니다. 개체 배열이있는 응용 프로그램에서 작업하고 있습니다. 이러한 각 객체는 객체의 배열을 가질 수 있으므로 탐색 목적으로 해당 마스터 객체에 대한 포인터를 갖습니다. 이러한 개체 중 하나의 복사본을 만들려고 할 때 메모리 누수가 발생합니다. iphone copyWithZone memory leak - 도움이 필요합니다.
@interface ListItem : NSObject <NSCopying> {
ListItem *MasterItem;
NSString *strText;
NSMutableArray *listItems;
BOOL boolDone;
NSDate *itemDate;
}
@property (nonatomic, retain) ListItem *MasterItem;
@property (nonatomic, retain) NSString *strText;
@property (nonatomic, retain) NSMutableArray *listItems;
@property (nonatomic, retain) NSDate *itemDate;
@property BOOL boolDone;
@end
@implementation ListItem
@synthesize strText, listItems, boolDone, MasterItem, itemDate;
- (id) init
{
if (self = [super init])
{
self.strText = nil;
self.listItems = nil;
self.itemDate = nil;
self.boolDone = FALSE;
self.MasterItem = nil;
}
return self;
}
-(id)copyWithZone:(NSZone *)zone
{
ListItem *another = [[[self class] allocWithZone:zone] init];
another.MasterItem = [MasterItem copyWithZone:zone];
another.listItems = [listItems copyWithZone:zone];
another.strText = [strText copyWithZone:zone];
another.itemDate = [itemDate copyWithZone:zone];
another.boolDone = boolDone;
return another;
}
-(void) dealloc
{
if (itemDate != nil)
[itemDate release];
if (MasterItem != nil)
[MasterItem release];
if (strText != nil)
[strText release];
if (listItems != nil)
[listItems release];
[super dealloc];
}
@end
내가이를 호출하고
, 메모리 누수 :ListItem *itemMasterToSave = [itemMaster copy];
[itemMasterToSave release];
어떻게 'MasterItem'이 파란색으로 변하는 지 확인해주세요. 그것이 그것이 클래스 이름이라고 생각하기 때문입니다. 규칙을 따르려면'masterItem'이어야합니다. – bbum