deephacks / lmdbjni

LMDB for Java
Apache License 2.0
204 stars 28 forks source link

Native object has been freed #46

Closed manjeet1198 closed 8 years ago

manjeet1198 commented 8 years ago

Hi, I am using lmdbjni 0.4.4 . first time when i was putting (Key, value) in db, it was working well , but now my program is throwing LMDBException : Native object has been freed

at org.fusesource.lmdbjni.NativeObject.checkAllocated(NativeObject.java:49) at org.fusesource.lmdbjni.NativeObject.pointer(NativeObject.java:39) at org.fusesource.lmdbjni.Env.createTransaction(Env.java:444) at org.fusesource.lmdbjni.Env.createWriteTransaction(Env.java:402) at org.fusesource.lmdbjni.Database.put(Database.java:360) at org.fusesource.lmdbjni.Database.put(Database.java:352)

krisskross commented 8 years ago

Can you show the code where this error originated from?

manjeet1198 commented 8 years ago

public class className{ public static Database getDB() { try (Env env = new Env("/tmp/mydb")) { try (Database db = env.openDatabase()) { return db; } } } }

from main() , Database db = className.getDB() ; db.put(bytes("Tampa"), bytes("rocks"));

krisskross commented 8 years ago

You are closing both Env and Database as you return from the try-with-resources code block in getDB method.