Why memory leaks occurs when using DataStore API o

2020-08-01 05:20发布

问题:

Could guys please help me find what causes memory leak ? It drives me crazy :(((

I'm using GAE SDK 1.6.1. I created sample project with single servlet that contains following doGet method

protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
{
    {
        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

        System.out.println();
        for (long i = 1; i <= 10000000; ++i)
        {
            Entity entity = new Entity("Visitor");
            entity.setProperty("name", "Name is " + i);
            entity.setProperty("value", "Value is " + i);
            Key key = datastore.put(entity);
            System.out.println(key.getId());
        }
    }
}

Call to this servlet fails with OutOfMemory exception because all temporary datastore objects remain in the memory.

Here is tree of incoming references to held object obtained using YourKit Java Profiler.

Does anybody know why? How can I avoid this? Is it GAE-specific bug or something in my development environment?

Thanks!!!

回答1:

I just found this thread where Ikai Lan (Google) says "The development server datastore stub is an in memory Map that is persisted to disk".

Perhaps it answers my question.