Memory leak in iOS Realm sdk

I was working on an iOS project where Realm sdk was used. When I checked the leaks instrument of Xcode, it kept on giving me memory leaks on creation of Realm instance. Then I created a very simple demo app using swiftui and Realm. I looked into memory leaks again and I see the leaks again. I want to know is there a way to get rid of these leaks cuz I checked on internet but there is no such solution.

Hi Rajat,

Thanks for posting and welcome to the community!
Could you please share more details about this such as a screenshot of what you’re seeing and/or logs when this happens.

Regards
Manny

View to show names list:

 import SwiftUI
  import RealmSwift

  struct NameListView: View {
      @ObservedResults(NameModel.self) var nameList

      var body: some View {

          List(nameList) { nameObj in
         Text(nameObj.name)
          }
      }
  }

Name model:

  class NameModel: Object, ObjectKeyIdentifiable {

      @Persisted(primaryKey: true) var id: Int
      @Persisted var name: String
  }

View to add names to Realm

  struct AddNameView: View {

      @State private var name: String = ""
      @ObservedResults(NameModel.self) var nameList

      var body: some View {

          HStack {
              TextField("Enter name here...", text: $name)
                  .textFieldStyle(.roundedBorder)

              Button {
                  let obj = NameModel()
                  obj.name = name
                 obj.id = nameList.count
                  $nameList.append(obj)
              } label: {
                  Text("Add")
                      .padding()
              }
          }
          .padding()
      }
  }

And this is my Home view

  struct HomeView: View {
      var body: some View {

          VStack{
              NameListView()
                  .padding(.bottom, 5)
              AddNameView()
                  .frame(height: 50)
          }
      }
  }

The screen looks like this

And the leaks instrument shows this plus as I add values sometimes more leaks shows up.