私は今これはばかげた質問ですが、私はまだこのケースについていくつかの貧弱な理解を持っています。これはメモリ管理と参照カウントに関するものです。コピー、割り当て、および可変コピーを使用すると、参照カウントがいくつ増えるかについて疑問があります。これは私が持っているコードです:
これはmyController.hです:
#import <UIKit/UIKit.h>
@interface myController : UIViewController {
NSMutableString *mutableStringCode;
}
@property (nonatomic, copy) NSMutableString *mutableStringCode;
@end
これはmyController.mです
#import "myController.h"
@implementation myController
-(void)viewDidLoad{
mutableStringCode = [[NSMutableStringCode alloc]init];
[self refresh];
}
-(void)refresh{
NSMutableString *myFileContents = [NSMutableString stringWithContentsOfFile:localPath encoding:NSUTF8StringEncoding error:&error];
mutableStringCode = [myFileContents mutableCopy];
//another code
myFileContents = nil;
}
-(void)dealloc{
[mutableStringCode release];
[super dealloc];
}
@end
このコードでは、いくつか疑問があります。1.そのmutableStringCodeで参照カウントがいくつ増えるか。2. notmutableStringCode
を使用してプロパティを設定する本当の方法ですか?3.プロパティにコピーを設定した後でも、それを割り当てる必要がありますか?copy
retain
mutableStringCode
誰かが私にそれを説明できますか?ありがとうございました