2011-05-04 5 views
1

내 UIImage에서 발생하는 누수가 있다고 생각합니다. 사실,내 UIImage에서 누수를 찾지 못했어요

// Create and posit the UIImage 
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]]; 
NSLog(@"retain count 1 : %i", [imageView retainCount]); 
imageView = [[UIImageView alloc] initWithImage:image]; 
NSLog(@"retain count 2 : %i", [imageView retainCount]); 
//[imageView setImage:image]; 
//[imageView initWithImage:image]; 
imageView.frame = CGRectMake(0,64,320,367); 
NSLog(@"retain count 3 : %i", [imageView retainCount]); 
[self.view addSubview:imageView]; 
NSLog(@"retain count 4 : %i", [imageView retainCount]); 
[imageView release]; 
NSLog(@"retain count 5 : %i", [imageView retainCount]); 
NSLog(@"-----------------------"); 

그 코드가 줘 ...이 다운로드 한 이미지를 많이하고 나는 새로운 사진을 다운로드 할 때, 그것은 기존의 상단 보였다 있다고 생각하고 이전 출시 할당 해제되지 않았거나 그 결과는 :

retain count 1 : 0 
retain count 2 : 0 
retain count 3 : 1 
retain count 4 : 1 
retain count 5 : 2 
retain count 6 : 1 
----------------------- 
retain count 1 : 0 
retain count 2 : 0 
retain count 3 : 1 
retain count 4 : 1 
retain count 5 : 2 
retain count 6 : 1 
----------------------- 
retain count 1 : 0 
retain count 2 : 0 
retain count 3 : 1 
retain count 4 : 1 
retain count 5 : 2 
retain count 6 : 1 
----------------------- 

분명히, 이미지가 발표 된 단지 1가,하지만 ... 분명히 ...

하면 화면에 더 많은 사진을, 어떻게 휴대 전화의 화면에 여전히 나이가있는 경우 나는 더 오래된 그림을 풀어 놓을 수 있냐?

내 질문을 읽어 주셔서 감사합니다 !!!

+0

의 이미지 속성을 설정해야합니다! – clement

답변

0
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
imageView.frame = CGRectMake(0,64,320,367); 
[self.view addSubview:imageView]; 
[imageView release]; 
} 

당신은 할당 된 imageView

+0

[imageView release]를 입력해야합니다. 그 줄의 두 번째 호출하기 전에 그래서 ??? – clement

0

당신은 ALLOC이미지 뷰 있습니다 release 그것을 해제하지 않아야합니다.

보기에서 추가 한 후에 해제하십시오.

[imageView release]; 
+0

Bhalara가 view.addSubView : imageView 다음에 ImageView를 릴리스하면 이전처럼 결과가 많이 보입니다. – clement

+0

그러면 imageView를 전역으로 만든 다음 이미지를 변경하는 것이 좋습니다. –

+0

@Cheltan Bhalara : 좋아, 내가 그랬지 만 [imageView setImage : image] 또는 [imageView initWithImage : image]가 imageView = [[UIImageView alloc] initWithImage : image]를 올바르게 대체하지 못합니다. ... – clement

0

오히려 매번 연결 완료를 새로운 이미지 뷰를 만드는 대신, 당신은 단지 내 코드를 업데이트했습니다 이미지 뷰

+0

도움 주셔서 감사합니다! 그래서 UIImageView를 proprety로 넣을 수 있으며 어떻게이 라인을 바꿀 수 있습니까? UIImageView * imageView = [[UIImageView alloc] initWithImage : image]; ?? – clement

+0

클래스의 UIImageView * imageView 속성을 만듭니다. 그럼 당신은 단지 코드 수 있습니다 : self.imageView.image = image; – Tomen

+0

그래, 고맙지 만, 나는 만들었지 만 표시되는 이미지가 없다 .. 나는 self.imageView.image = image; imageView = [[UIImageView alloc] initWithImage : image]를 사용하기 전에; – clement

관련 문제