我正在编写一个简单的 Scala & Squeryl 应用程序。出于测试目的,每次我在 sbt 中运行“测试”时,都会创建一个内存 H2 数据库并填充测试数据。每次运行后,我可以看到任务管理器中 java.exe(在其中运行 sbt)的内存使用量增加,直到运行 4 或 5 次后,它会因 OutOfMemoryError 而崩溃。我是否遗漏了一些明确释放 H2 或 Squeryl 使用的内存的东西?到目前为止,我只使用Session.create
then Persistence.create
。这是我的代码的摘录:
object Persistence extends Schema {
val documents = table[IncomeEntity]
val positions = table[Position]
val documentToPositions = oneToManyRelation(documents, positions).via(_.id === _.id_income)
}
class PersistenceTests extends FunSuite with BeforeAndAfterAll {
override protected def beforeAll() {
Class.forName("org.h2.Driver")
SessionFactory.concreteFactory = Some(
() => Session.create(DriverManager.getConnection("jdbc:h2:mem:test"), new H2Adapter)
)
}
test("DDL") {
transaction {
Persistence.create
assert(Persistence.documents.size == 0)
assert(Persistence.positions.size == 0)
}
}
test("Insert") {
transaction {
Persistence.create
(1 to 100) map { _ => IncomeMapper.save(new Income) }
assert(Persistence.documents.size == 100)
}
}
}
我收到的消息如下:
[info] PersistenceTests:
sbt appears to be exiting abnormally.
The log file for this session is at C:\Users\Oleg\AppData\Local\Temp\sbt7320472784033855835.log
java.lang.OutOfMemoryError: PermGen space
Error during sbt execution: java.lang.OutOfMemoryError: PermGen space