将对象持久保存到 GAE 数据存储中后发生内存泄漏
你们能帮我找出内存泄漏吗?我来自 C++ 世界,Java 中的内存泄漏对我来说有点奇怪,因为根据我的代码,我没有保留对临时对象的引用。
我正在使用 GAE SDK 1.6.1 和 Objectify 3.1。
我有以下方法正在 GAE 开发服务器的后端实例中执行(这可能与问题无关)。
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;
}
在 ObjectifyDAO 的构造函数中,它被初始化为
public ObjectifyDAO()
{
super(new ObjectifyOpts().setSessionCache(false).setGlobalCache(false));
}
Visitor
就像
public class Visitor
{
@Id
Long key;
Long ek;
@Unindexed String ip;
Date t;
@Unindexed Long lzVisit;
}
我使用 JProfiler 7.0.1 来捕获内存泄漏一样简单。运行此代码后,我有几兆字节的 com.google.storage.onestore.v3.OnestoreEntity$PropertyValue
和 com.google.storage.onestore.v3.OnestoreEntity$Property
。
我不想炸毁这篇文章,所以我上传了 JProfiler 的屏幕截图。
我在 Objectify 的跟踪器上发现了此错误,并且Google Ground 上的此帖子盖伊。所以我不确定这是谁的错误。
问题是:
1)如何避免内存泄漏? 2)生产中会发生这种情况吗?
谢谢!!!
附言。尼克,我知道你正在读这篇文章。请帮忙:)
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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看http://www.eclipse.org/mat/,它非常适合分析内存泄漏
请参阅http://wiki.eclipse.org/index.php/MemoryAnalyzer#Getting_a_Heap_Dump
如果存在内存泄漏,则表明某些内容挂在引用上。像 MAT 这样的工具将帮助您查看这些对象上挂着什么。
另外,您可能想在生产中尝试测试。您可以在 appspot.com 实例视图上检查内存使用情况。生产应用程序引擎有时表现得非常不同。
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.