Skip to content

Instantly share code, notes, and snippets.

@amay077
Last active December 22, 2015 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amay077/6412557 to your computer and use it in GitHub Desktop.
Save amay077/6412557 to your computer and use it in GitHub Desktop.
ARC のメモリ解放タイミングを調べた ref: http://qiita.com/amay077/items/95a4139e6f553d8a56a1
- (IBAction)buttonDownWithArc:(id)sender {
NSString* path = @".../bigdata.img";
for (int i = 0; i < 10000; i++) {
NSData* data = [NSData dataWithContentsOfFile:path];
[NSThread sleepForTimeInterval:0.5];
data = nil;
}
}
- (IBAction)buttonDownNoArc:(id)sender {
NSString* path = @".../bigdata.img";
for (int i = 0; i < 10000; i++) {
NSData* data = [NSData dataWithContentsOfFile:path];
[NSThread sleepForTimeInterval:0.5];
[data dealloc];
data = nil;
}
}
- (IBAction)buttonDownWithArcAndAutoRelease:(id)sender {
for (int i = 0; i < 100; i++) {
@autoreleasepool {
NSData* data = [NSData dataWithContentsOfFile:_path];
[NSThread sleepForTimeInterval:0.5];
}
}
}
for (int i = 0; i < 画像数; i++) {
/*
* 画像読み込み処理
* autoreleaseされたオブジェクトが大量発生。
* NSAutoReleasePoolのオブジェクトが破棄されないため
* いずれメモリ不足発生!
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment