Skip to content

flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: IsarError: Cannot open Environment: MdbxError (12): Cannot allocate memory #1527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
elite-kai opened this issue Jan 7, 2024 · 5 comments

Comments

@elite-kai
Copy link

Hello, I have a problem here. When I run it on iphoneX, I get this error: Unhandled Exception: IsarError: Cannot open Environment: MdbxError (12): Cannot allocate memory. I have no problem running it on iPhone11 or above. I searched for relevant knowledge and found that the running memory of iPhone11 and above mobile phone models is 4G, and the running memory of iPhoneX is 3G. My application content is mainly related to data storage, and I need to store a lot of data, so I created 6 Isar instances for different scenarios, which resulted in the error Unhandled Exception: IsarError: Cannot open Environment: reported on iphoneX. MdbxError (12): Cannot allocate memory. But if I set the maxSize parameter to be smaller, for example, if several isars are set to 100, there will be no problem when running. What does maxSize mean? Does it mean setting the maximum running memory? If I set all maxSizes to 100, but the data I need to store may be several gigabytes in size, will there be a problem?

@elite-kai
Copy link
Author

It seems that the maxSize parameter will be affected by the running memory of the mobile phone. If the mobile phone is relatively low-end and I create multiple isars to store different functional data, then this error MdbxError (12): Cannot allocate memory will be reported.

@shahmirzali49
Copy link

I have this issue too. maxSizeMiB: 3072000, changed to default Isar.defaultMaxSizeMiB it works.

@lvyandev
Copy link

lvyandev commented Oct 25, 2024

But the default size is already specified to Isar.defaultMaxSizeMiB if null, isn't it?

factory _IsarImpl.open({
    required List<IsarGeneratedSchema> schemas,
    required String name,
    required IsarEngine engine,
    required String directory,
    required int? maxSizeMiB,
    required String? encryptionKey,
    required CompactCondition? compactOnLaunch,
    String? library,
  }) {
    IsarCore._initialize(library: library);

    if (engine == IsarEngine.isar) {
      if (encryptionKey != null) {
        throw ArgumentError('Isar engine does not support encryption. Please '
            'set the engine to IsarEngine.sqlite.');
      }

      // look at this line
      maxSizeMiB ??= Isar.defaultMaxSizeMiB;
    } else {
      if (compactOnLaunch != null) {
        throw ArgumentError('SQLite engine does not support compaction.');
      }
      maxSizeMiB ??= 0;
    }

@mars3142
Copy link

mars3142 commented Nov 6, 2024

I also wanted to know the meaning of the maxSize. Our size was set to number x and after a while we couldn't write data into the database.

So it could be related to the file size AND memory size. Which is completely wrong in my opinion. Why should the developer set a hard limit for a file size (it's not a log file, which should be limited)? We don't know how many data the user will save. It should grow as much as the device has internal storage.

And the observation, that low end devices will crash, seems to show, that the complete database is also in RAM (like redis or memcache). I don't need this behavior.

It always drills down to the question: what is maxSize for?

@lvyandev
Copy link

I also wanted to know the meaning of the maxSize. Our size was set to number x and after a while we couldn't write data into the database.

So it could be related to the file size AND memory size. Which is completely wrong in my opinion. Why should the developer set a hard limit for a file size (it's not a log file, which should be limited)? We don't know how many data the user will save. It should grow as much as the device has internal storage.

And the observation, that low end devices will crash, seems to show, that the complete database is also in RAM (like redis or memcache). I don't need this behavior.

It always drills down to the question: what is maxSize for?

Agree, this should be a bug that needs to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants