LoginSignup
8
5

More than 5 years have passed since last update.

Realm - Cannot allocate memory size: xxx offset: 0'

Posted at

遭遇したエラー

Realmを使っていて、以下のエラーに遭遇した。

*** Terminating app due to uncaught exception 'RLMException', reason: 'mmap() failed: Cannot allocate memory size: 603979776 offset: 0'
*** First throw call stack:
(0x181f5ee38 0x1815c3f80 0x1003fa84c 0x1003dbdd4 0x1003dc334 0x1003dce60 0x1003db150 0x100113520 0x100e01a7c 0x100e01a3c 0x100e10c9c 0x100e10364 0x181bc1470 0x181bc1020)
libc++abi.dylib: terminating with uncaught exception of type NSException

原因は、Realmのファイルサイズっぽい。公式にもちゃんと書いてある。

各Realmファイルのサイズは、アプリケーションごとにに割り当てられるメモリサイズを超えてはいけません。割り当てられるメモリサイズは、デバイスごとに異なり、実行時のメモリの断片化にも依存します。(詳しくは、rdar://17119975 をご覧ください)それ以上のデータを保存される場合は、Realmファイルを複数に分割してください。

抜粋 : 現バージョンにおける制限事項

ファイルのサイズを調べる

ファイルの情報は、 NSFileManagerの
- attributesOfItemAtPath:error:
メソッドを使えばファイルの情報を調べることができる。

NSString path = [RLMRealm defaultRealm].path;
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];

NSLog(@"attributes : %@", attributes);

出力結果がこちら

{
    NSFileCreationDate = "2016-03-25 00:04:17 +0000";
    NSFileExtensionHidden = 0;
    NSFileGroupOwnerAccountID = xxx;
    NSFileGroupOwnerAccountName = xxx;
    NSFileModificationDate = "2016-03-25 05:18:13 +0000";
    NSFileOwnerAccountID = xxx;
    NSFileOwnerAccountName = xxx;
    NSFilePosixPermissions = xxx;
    NSFileProtectionKey = NSFileProtectionCompleteUntilFirstUserAuthentication;
    NSFileReferenceCount = 1;
    NSFileSize = 603979776;
    NSFileSystemFileNumber = xxx;
    NSFileSystemNumber = xxx;
    NSFileType = NSFileTypeRegular;
}

NSFileSizeが、ファイルのサイズをbyteで表している。

[attributes valueForKey:NSFileSize];

しかし、 603979776 は bytesなので 576MB。そんなにデータ入れたかなぁ...。

8
5
2

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
8
5