Sorry in advance if this isn’t the right place to post this, I couldn’t find a real issue tracker (maybe I didn’t search enough). Please redirect me if that is the case.
I have been using Java Realm in the past for an Android app, that I migrated recently to Kotlin Multiplatform in order to make it compatible with iOS. After testing, it appears that by running it in an iOS environment, my memory was getting saturated by a leak, which affected both the RAM, and the disk (which it would fill up entirely in a few weeks of testing, all 64Gb). So I made a really simple downgraded version of it which showcases what exactly fails in it. In short, by calling the realm.open and realm.close methods, I leak memory (instances of realm_scheduler according to my memory graph on Xcode, but anything related to realms seems to create a way too large amount of instances in it).
Here’s a repo to reproduce the error : GitHub - ALXgba/realmKMMIssue: Memory leak using Kotlin API in a KMM project, when run in iOS environment.
As you can see, my Kotlin code only opens a realm instance with a test class before closing it. And I do this every .1s in my iOS code. That’s it. If the same operation is done in its Android counterpart, there is no memory leak. (Sorry, I realize that I didn’t edit this code to also execute the same way in Android. If you wish to test it, you can simply instantiate a RealmLeaker and have it run RealmLeaker.leak() in a while loop).
Possible duplicate without resolution → Memory leak in iOS Realm sdk - #3 by Rajat_Dhasmana