-3

내 응용 프로그램에서 전역 변수를 선언하는 클래스를 하나 만들었습니다.언제 ARC에서 변수를 공개하거나 없앨까요?

.H 파일

@interface GlobalVariables : NSObject 

@property (nonatomic, strong) NSString *strTemp1; 
@property (nonatomic, strong) NSArray *arrTemp1; 

+ (GlobalVariables *)sharedInstance ; 

하는 .m 파일 일부 클래스 이제

#import "GlobalVariables.h" 

@implementation GlobalVariables 

+ (GlobalVariables *)sharedInstance 
{ 
    static GlobalVariables *sharedInstance = nil; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     sharedInstance = [self new]; 
     // Do any other initialisation stuff here 
     NSLog(@"alloc and intialize"); 
    }); 
    return sharedInstance; 
} 

, 나는이 변수의 값을 설정합니다.

[[GlobalVariables sharedInstance] setStrTemp1:@"Temp1"]; 
[[GlobalVariables sharedInstance] setArrTemp1:[NSArray arrayWithObjects:@"Name",@"Address",@"Contact NO", nil]]; 

또한 다른 클래스에서이 값을 가져옵니다.

NSLog(@"Get string value : %@", [[GlobalVariables sharedInstance] strTemp1]); 
NSLog(@"Get arr value : %@", [[GlobalVariables sharedInstance] arrTemp1]); 

이제 내 질문은이 변수가 릴리스 또는 nil 일 때입니까?

프로젝트에서 ARC를 사용하고 있습니다.

호가 자동으로 출시된다는 것을 알고 있지만 언제, 어떻게 사용합니까?

+1

ARC를 사용하는 경우 실제로 메모리를 해제하는시기와 방법을 신경 쓰지 않아야합니다. – FreeAsInBeer

+0

before iOS 5 ARC mens에 대한 개념이 없으므로 작성한 모든 객체를 해제해야합니다 ...... 거기에 아무 것도 잊어 버리면 경고 메시지가 나타납니다. 따라서 iOS 5 이후에는 ARC (Automatic Reference counting) ... 객체를 할당하고 아무 문제없이 잊어 버리십시오. –

답변

2

이것은 싱글 톤 클래스이며 앱을 끝내거나 다른 이유로 앱이 종료 될 때까지 속성이있는 클래스가 활성화됩니다.

+0

또는 그것에 nil을 지정하면됩니다. – GoodSp33d

+0

만약 그 객체에 아무런 값도 없다는 것을 의미하는 nil을 지정하면 ... 그 객체의 참조가 남아 있습니다 ... –

+0

그래서 참조를 제거하기 위해 ARC 앞에 객체를 놓아야합니다. 무료 메모리 –