Steps:
Every time the doGet method is called, I get another instance of MappedClass which is indeed the class the DAO is for. No other obvious classes are leaking (except the MappedFields that are part of the MappedClass) - one Mapper, one DatastoreImpl, one MongoManager (see below), no DAO or model classes.
I've run the same test without the DAO, just using my MongoManager to get the Datastore and using that directly to read the db. That works fine - no leaks.
Here's some code:
public class TesterDao extends BasicDAO<Tester, ObjectId> {
public TesterDao() {
super(Tester.class, MongoManager.instance().getDb());
}
}
public class MorphiaTestServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
TesterDao testerDao = new TesterDao();
}
}
public class MongoManager {
private static final MongoManager INSTANCE = new MongoManager();
private final String MONGO_HOST = "localhost";
private final int MONGO_PORT = 27017;
private Datastore theDb = null;
private MongoManager() {
Mongo mongo;
try {
mongo = new Mongo(MONGO_HOST, MONGO_PORT);
theDb = new Morphia()
.map(Tester.class)
.createDatastore(mongo, "MorphiaTest");
theDb.ensureIndexes();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (MongoException e) {
e.printStackTrace();
}
}
public static MongoManager instance() {
return INSTANCE;
}
public Datastore getDb() {
return theDb;
}
}