Should I worry about closing the Realm database in Objective-C and Swift?

The Java documentation for the Realm class has a close method. It is written in the details of the method: "It is important to always remember to close Realm instances when you are done with it, so as not to leak memory, file descriptors or increase the size of the Realm file without flickering."

Neither the Objective-C document for the RLMRealm class , nor the Swift documentation for the Realm class show anything like this.

Do I need to worry about closing the Realm database in Objective-C and Swift? Why are these differences between platforms?

+7
java objective-c swift realm
source share
2 answers

No, you do not need to worry about closing the database.

If Realm does not provide a close method, closing is done by Realm itself. As you mentioned, there are differences between different platforms / operating systems.

+4
source share

The difference is associated with different memory management schemes. Objective-C and Swift are reference counting, while Java on Dalvik and ART uses a garbage collector for marking and markup. This means that in obj-c and swift objects, objects are freed as soon as the last reference to them is released (or when the autostart pool merges), while in Java objects they can exist for as long as necessary if the application is not under memory pressure As a result, Java objects cannot reliably copy automatic memory management to clear a resource without memory, but sometimes Objective-C and Swift objects may exist.

+2
source share

All Articles