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