내가로드 내 jQuery과 방법 cellAtRowForIndexPath 내부 사람 개체어떻게 메모리가 누출됩니까?
에게 Person.h
#import <UIKit/UIKit.h>
#import "TwitterHelper.h"
@interface Person : NSObject {
NSDictionary *userInfo;
NSURL *image;
NSString *userName;
NSString *displayName;
NSArray *updates;
}
/*
@property (retain) NSString *userName;
@property (retain) NSString *displayName;
@property (retain) NSDictionary *userInfo;
*/
@property (nonatomic, copy) NSURL *image;
@property (retain) NSArray *updates;
- (id)initWithUserName:userName;
@end
Person.m
#import "Person.h"
@implementation Person
/*
@synthesize userName;
@synthesize displayName;
@synthesize userInfo;
*/
@synthesize image;
@synthesize updates;
- (id)initWithUserName:(NSString *)user{
userName = user;
userInfo = [TwitterHelper fetchInfoForUsername:user];
displayName = [userInfo valueForKey:@"name"];
image = [NSURL URLWithString:[userInfo valueForKey:@"profile_image_url"]];
updates = [TwitterHelper fetchTimelineForUsername:userName];
return self;
}
- (void)dealloc
{
/*
[userName release];
[displayName release];
[updates release];
[userInfo release];
[image release];
*/
[super dealloc];
}
@end
을 만들 때 나는 각 사람 개체를 만드는 오전 테이블보기를 가지고 이미지 속성을 할당하면 ...
Person *person = [[Person alloc] initWithUserName:userName];
NSData *data = [[NSData alloc] initWithContentsOfURL:person.image];
[data release];
인스 트루먼 테이션에서 이것을 실행하면 NSData * 데이터 ... 행이 누설되는 부분을 강조 표시합니다.
왜 누수가 있습니까? 당신이 속성을 만들하기로 선택한 경우
속성을 선언하는 방식 (원자, 유지, 복사 등)에 차이가 있습니까? – Jason
글쎄, 나는 그것이 차이를 만들어 낸다는 것을 말해야한다. 그러나 나의 위의 예에서는 무엇이되어야 하는가? – Jason
No! 이니셜 라이저 또는 dealloc 메소드에서 접근 자 (명시 적으로 또는 점 표기법을 통해)를 사용하지 않아야합니다. 이 메서드에서는 직접 속성 액세스 *를 사용합니다.getter/setter를 호출하면이 두 상황에서 의도하지 않은 (부적절한) 결과가 발생할 수 있습니다. 그러나 * NSURL을 복사해야합니다. Cocoa 용 메모리 관리 안내서를 다시 읽어야합니다. –