Skip to content
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

malloc_ptr classes(objc_copyClassList(&numClasses), &free); crash #8026

Closed
huanglins opened this issue Nov 11, 2022 · 7 comments
Closed

malloc_ptr classes(objc_copyClassList(&numClasses), &free); crash #8026

huanglins opened this issue Nov 11, 2022 · 7 comments

Comments

@huanglins
Copy link

huanglins commented Nov 11, 2022

How frequently does the bug occur?

All the time

Description

Crashing on iOS 14.1, iOS 14.8 devices

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

try? Realm(configuration: config)

let rlmRealm = try RLMRealm(configuration: configuration.rlmConfiguration, queue: queue)

RLMSchema *schema = configuration.customSchema ?: RLMSchema.sharedSchema;

malloc_ptr classes(objc_copyClassList(&numClasses), &free); -> crash

Version

10.20 、10.32.3

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iOS

Build environment

Xcode version: ... 14.1
Dependency manager and version: ... pod 1.11.3

@huanglins
Copy link
Author

When i added monitorextension i got this error

@huanglins
Copy link
Author

After specifying objectTypes in Realm.Configuration, the startup will not crash, but you can still hope to fix the problem

@dianaafanador3
Copy link
Contributor

Hi @huanglins from what I can understand your issue disappeared when specifying the objectTypes you want in your schema, which means that this issues is happening when doing a complete discovery to build the schema. When you open the realm we do a schema discovery for all the classes and then filter the ones that inherit from Object or RLMObject so we can build the schema for the realm.
You mentioned that this is happening when adding a monitor extension which makes me suspect that objc_copyClassList() is crashing due to running out of memory.

We could probably document this better, but your solution is right now the best to solve this issue.

@kaibaaqua
Copy link

I have the same problem with Realm 10.32.3, but it was OK with Realm 10.27.0.

I don't know what the monitorextension is.

By applying @huanglins 's workaround (specifying the objectTypes).

@liujieyuu
Copy link

liujieyuu commented Mar 7, 2024

Let me give you an example:
let config = Realm.Configuration(fileURL: URL(string: fileURL), schemaVersion: schemaVersion,migrationBlock: { (migration, oldSchemaVersion) in
// 目前我们还未进行数据迁移,因此 oldSchemaVersion == 0
if oldSchemaVersion < 1 {
// 什么都不要做!Realm 会自行检测新增和需要移除的属性,然后自动更新硬盘上的数据库架构
}
// 低版本的数据库迁移......
if migrationBlock != nil {
migrationBlock!(migration, oldSchemaVersion)
}
}, objectTypes: [GoodsItermModel_db.self])

@nirinchev look this

@nirinchev
Copy link
Member

This is definitely not enough information to reproduce the issue - it shows creating a simple config and we have many tests that verify code like this works. If you can reproduce a crash in a simple and isolated project, please share the entire project.

@liujieyuu
Copy link

Suffice it to say, this is a temporary solution, after all, such a crash is not guaranteed, thank you. @nirinchev

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants