0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

メモリ管理.インスタンス変数

Last updated at Posted at 2014-02-07

#インスタンス変数は、viewDidLoadで初期化、viewDidUnloadで解放

  • すべてのインスタンス変数 ⇒ deallocで解放
  • initで初期化する変数 ⇒ deallocで解放。
  • viewDidLoadで初期化する変数 ⇒ viewDidUnLoadとdeallocで解放。

参照


@interface ExampleViewController : UIViewController{

	NSMutableArray *obj1; // viewDidLoadで初期化する
	NSMutableArray *obj2; // viewDidLoadで初期化しない

}

- (void) viewDidLoad
{
	
	obj1 = [[NSmutableArray alloc] init];

}

- (void) viewDidUnload
{

	[obj1 release];
	obj1 = nil; // deallocで再度releaseされたときにクラッシュしないようにnilを入れておく。nilに対してreleaseされても何も起きないので。
 
}

- (void) dealloc
{

	[obj1 release];
	[obj2 release];

}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?