gpt4 book ai didi

java - Junit testing in play with java.lang.OutOfMemoryError 已被捕获,Java 堆空间

转载 作者:行者123 更新时间:2023-11-28 20:56:27 26 4
gpt4 key购买 nike

我正在尝试对网络应用程序进行一些 junit 测试,但我不断收到 OutOfMemoryError。我知道它在代码中发生的位置,但我不确定它为什么这样做。

Survey survey = new Survey();
SurveyLayoutColumn column1 = new SurveyLayoutColumn();
column1.addAnswerSpace(new Answer());
SurveyLayoutColumn column2 = new SurveyLayoutColumn();
column2.addAnswerSpace(new Answer());
column2.addAnswerSpace(new Answer());
SurveyLayoutColumn column3 = new SurveyLayoutColumn();
column3.addAnswerSpace(new Answer());
survey.addLayoutColumn(column1);
survey.addLayoutColumn(column2);
survey.addLayoutColumn(column3);
survey.addQuestion(new Question());
survey.addQuestion(new Question());
survey.addQuestion(new Question());
survey.addQuestion(new Question());
Application app = new controllers.Application();
app.saveSurvey(survey);
long count = Survey.count();
assertEquals(count,0);

它发生在 app.saveSurvey(surey) 中,这是该方法的代码

public static void saveSurvey(Survey survey) {
System.out.println("Survey title is: " + survey.title);

survey.published = true;
survey.save();

Map<String, Object> viewData = new HashMap<String, Object>();

viewData.put("status", "success");

JSONSerializer serializer = new JSONSerializer();

serializer
.include("status")
.exclude("*");

renderJSON(serializer.serialize(viewData));
}

任何帮助都会很好地解释为什么会发生这种情况。

编辑:这是轨迹

java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390)
at java.lang.StringBuilder.append(StringBuilder.java:119)
at play.data.binding.Unbinder.unBind(Unbinder.java:106)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:63)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:63)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:63)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:63)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:63)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:63)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:63)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:63)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)
at play.data.binding.Unbinder.unBind(Unbinder.java:63)
at play.data.binding.Unbinder.unBind(Unbinder.java:110)

最佳答案

好吧,看起来 Unbinder.unbind() 处于循环中,调用自身,并且在每次调用时它吸收一点内存;它可以使用它在每次调用时使用的堆栈或连接到 AbstractStringBuilder 的东西来做到这一点。

Out of Memory 是堆栈跟踪不一定指向问题行的一次;在这些情况下,堆栈跟踪通常会显示一些类似这样的循环。

关于java - Junit testing in play with java.lang.OutOfMemoryError 已被捕获,Java 堆空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15340898/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com