iOS 5 SDK를 사용하여 iOS 앱을 개발 중입니다. 자동 참조 횟수 기능이 활성화되어 있습니다. 그러나 나는 많은 수의 객체를 생성하고 있으며, 1 초 후에 배포되어야한다. 그렇지 않으면 디바이스가 매우 느려지 게 될 것이기 때문이다. 기기가 매우 느려서 출시되지 않은 것 같습니다. ARC를 사용할 때 수동으로 개체를 해제 할 수 있습니까?iOS : ARC를 사용하는 상태에서 메모리에서 객체를 제거하는 방법은 무엇입니까?
EDIT : 내 코드.이 코드는 반짝임을 생성하기 위해 초당 200 번 호출됩니다. 그들은 0.8 초 후에 페이드 아웃하기 때문에 그 이후에는 쓸모가 없습니다.
int xanimationdiff = arc4random() % 30;
int yanimationdiff = arc4random() % 30;
if (arc4random()%2 == 0) {
xanimationdiff = xanimationdiff * -1;
}
if (arc4random()%2 == 0) {
yanimationdiff = yanimationdiff * -1;
}
Sparkle *newSparkle = [[Sparkle alloc] initWithFrame:CGRectMake(20 + arc4random() % 280, 20, 10, 10)];
//[newSparkle setTransform:CGAffineTransformMakeRotation(arc4random() * (M_PI * 360/180))]; //Rotatie instellen (was niet mooi, net sneeuw)
[self.view addSubview:newSparkle];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[newSparkle setFrame:CGRectMake(newSparkle.frame.origin.x - xanimationdiff, newSparkle.frame.origin.y - yanimationdiff, newSparkle.frame.size.width, newSparkle.frame.size.height)];
newSparkle.alpha = 0;
[UIView commitAnimations];
스파클 오브젝트 코드 : 당신은 여전히 (NB를 CoreFoundation에서 객체를 유지하고 해제 할 수 있지만
ARC와#import "Sparkle.h"
@implementation Sparkle
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"sparkle.png"]]];
}
return self;
}
@end
질문에 제 코드를 추가했습니다. – icant
'nil'으로 객체를 설정할 수 없습니까? 루프에서 많은 NSArray 및 Dictionary 객체를 작성하고 전역 배열에 추가하기 때문에 걱정이됩니다. 따라서 나중에 필요하지 않습니다. ARC가 루프에 구축 된 객체를 제거하는 방법은 무엇입니까? – applefreak
그건 어떻게 작동하는지는 잘 모르겠다. for 루프로 객체를 만들고 전역 배열에 추가하면 여전히 유지 될 것이다. 전역 배열에서 * 제거 * 될 때까지는 해제 할 수 없습니다 (즉, 보유 계수가 0 임). – lxt