realm-swift: Instantiating first Realm causes memory leak originating in Swift reflection code

I’ve started trying to fix memory leaks on an app, and noticed that there seems to be a leak when instantiating a Realm.

Here’s example project where I’ve included a few screenshots and the Instruments trace showing the problem.

https://github.com/jviney/realm-memory-leak-test

Screenshot 1 Screenshot 2 Screenshot 3

The number of objects leaked correlates with the number of properties your Realm objects have. If you comment out the definition of the Person class the leak is smaller.

Thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

Whatever the cause, this leak still seems to be happening with Realm 0.103.1 and Xcode 7.3.1:

image

The leak as reported by @jviney (and demonstrated in his test project) appears to be fixed as of Xcode 8.3 with Swift 3.1. I’ve shared the updated project I tested with at https://github.com/bdash/realm-memory-leak-test.

If anyone is seeing leaks of any kind with Xcode 8.3 and Swift 3.1, it is very likely to be a different issue than was originally reported here. You’ll need to file new issues about what you’re seeing since the problem this GitHub issue was tracking has been fixed.

We are seeing the same thing on the current version of SwiftRealm and would love to get this cleaned up.

Also here, always getting a leak in Realm()