Could you guys please help me find memory leak ? I’m from C++ world and memory leaks in Java are kinda strange thing to me since according to my code I keep no references to temporary object.
I’m using GAE SDK 1.6.1 and Objectify 3.1.
I have following method which is being executed in backend instance of GAE dev server (which is probably irrelevant info to the issue).
private void loadProtoBufdata() throws Exception
{
ObjectifyDAO dao = new ObjectifyDAO();
for (long count = 0; count < 100; ++count)
{
Visitor visitor = new Visitor();
visitor.setKey(count + 1);
dao.ofy().put(visitor);
}
dao = null;
}
In constructor of ObjectifyDAO it’s being initialized as
public ObjectifyDAO()
{
super(new ObjectifyOpts().setSessionCache(false).setGlobalCache(false));
}
And Visitor is as simple as
public class Visitor
{
@Id
Long key;
Long ek;
@Unindexed String ip;
Date t;
@Unindexed Long lzVisit;
}
I’m using JProfiler 7.0.1 to catch memory leaks. After running this code I have few megabytes of com.google.storage.onestore.v3.OnestoreEntity$PropertyValue and com.google.storage.onestore.v3.OnestoreEntity$Property.
I don’t want to blow up this post so I uploaded screenshots from JProfiler.
Reference tree is here. Allocation tree is here.
I found this bug on Objectify’s tracker and also this thread on Google Ground for GAE. So I’m not sure whose bug this is.
Questions are:
1) How to avoid memory leak?
2) Does it happen in production?
Thanks!!!
PS. Nick, I know you are reading this. Please help 🙂
Check out http://www.eclipse.org/mat/ which is great for analysing memory leaks
See http://wiki.eclipse.org/index.php/MemoryAnalyzer#Getting_a_Heap_Dump
If there is a memory leak, something is hanging on to references. A tool like MAT will help you see what is hanging on to those object.
Also, you may want to try your test on production. You can check the memory use on the appspot.com instances view. Production appengine can sometimes behave quite differently.