Remember to call close() on all Realm instances but everything should be closed

Viewed 1063

im having a workflow inside my app where the user can save something and after that a dialog appears with the hint to login. Inside my Android monitor the following Warning shows up: "Remember to call close() on all Realm instances. Realm /data/data/files/default.realm is being finalized without being closed, this can lead to running out of native memory."

Ive read the documentation (https://realm.io/docs/java/latest/) where the advice is to use "try-with-resources" (https://realm.io/docs/java/latest/#closing-realm-instances). So every Realm Transaction is inside

try (Realm realm = Realm.getDefaultInstance()) {
// No need to close the Realm instance manually
}

and inside this block im using

                realm.executeTransaction(new Realm.Transaction() {
                @Override
                public void execute(Realm realm) {
                    // do Something
                }
            });

So in conclusion:

try (Realm realm = Realm.getDefaultInstance()) {
 realm.executeTransaction(new Realm.Transaction() {
                @Override
                public void execute(Realm realm) {
                    // do Something
                }
            });
}

Can anyone explain to me why this Warning shows up? Ive even tried to add a finally block where i close the Realm instance manually. But this does not avoid the warning. Thanks in advance!

1 Answers
Related