提交 88daf980 authored 作者: Thomas Mueller's avatar Thomas Mueller

There was a memory leak when creating and dropping tables.

上级 a7afe6b2
......@@ -115,6 +115,7 @@ public class BtreeIndex extends BaseIndex implements RecordReader {
public void remove(Session session) throws SQLException {
storage.truncate(session);
database.removeStorage(storage.getId(), storage.getDiskFile());
storage = null;
}
......
......@@ -62,6 +62,7 @@ public class ScanIndex extends BaseIndex {
truncate(session);
if (storage != null) {
storage.truncate(session);
database.removeStorage(storage.getId(), storage.getDiskFile());
}
}
......
......@@ -23,17 +23,18 @@ public class TestMemoryUsage extends TestBase {
private Connection conn;
private void reconnect() throws SQLException {
if (conn != null) {
conn.close();
}
// Class.forName("org.hsqldb.jdbcDriver");
// conn = DriverManager.getConnection("jdbc:hsqldb:test", "sa", "");
conn = getConnection("memoryUsage");
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws SQLException {
deleteDb("memoryUsage");
testCreateDropLoop();
testCreateIndex();
testClob();
deleteDb("memoryUsage");
......@@ -45,6 +46,35 @@ public class TestMemoryUsage extends TestBase {
insertUpdateSelectDelete();
conn.close();
}
private void testCreateDropLoop() throws SQLException {
conn = getConnection("memoryUsage");
Statement stat = conn.createStatement();
for (int i = 0; i < 100; i++) {
stat.execute("CREATE TABLE TEST(ID INT)");
stat.execute("DROP TABLE TEST");
}
int used = MemoryUtils.getMemoryUsed();
for (int i = 0; i < 1000; i++) {
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
stat.execute("DROP TABLE TEST");
}
int usedNow = MemoryUtils.getMemoryUsed();
if (usedNow > used * 1.3) {
assertEquals(used, usedNow);
}
conn.close();
}
private void reconnect() throws SQLException {
if (conn != null) {
conn.close();
}
// Class.forName("org.hsqldb.jdbcDriver");
// conn = DriverManager.getConnection("jdbc:hsqldb:test", "sa", "");
conn = getConnection("memoryUsage");
}
private void testClob() throws SQLException {
if (config.memory || !config.big) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论