attempt to fix a memory leak

This commit is contained in:
Louis Vallat 2019-05-03 23:27:54 +02:00
parent 1ce343d523
commit a5692db5b8
3 changed files with 18 additions and 12 deletions

View File

@ -19,7 +19,7 @@ is divided into following sections:
- cleanup
-->
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="twitter_techsupportgore_bot-impl">
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="TwitterTechSupportGoreBot-impl">
<fail message="Please build using Ant 1.8.0 or higher.">
<condition>
<not>
@ -450,7 +450,7 @@ is divided into following sections:
</fileset>
</union>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="twitter_techsupportgore_bot" testname="TestNG tests" workingDir="${work.dir}">
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="TwitterTechSupportGoreBot" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
<propertyset>
<propertyref prefix="test-sys-prop."/>
@ -601,7 +601,7 @@ is divided into following sections:
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
<isset property="test.method"/>
</condition>
<condition else="-suitename twitter_techsupportgore_bot -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
<condition else="-suitename TwitterTechSupportGoreBot -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
<matches pattern=".*\.xml" string="@{testClass}"/>
</condition>
<delete dir="${build.test.results.dir}" quiet="true"/>
@ -893,7 +893,7 @@ is divided into following sections:
<delete file="${built-jar.properties}" quiet="true"/>
</target>
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
<echo level="warn" message="Cycle detected: twitter_techsupportgore_bot was already built"/>
<echo level="warn" message="Cycle detected: TwitterTechSupportGoreBot was already built"/>
</target>
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
<mkdir dir="${build.dir}"/>
@ -1378,7 +1378,7 @@ is divided into following sections:
<delete file="${built-clean.properties}" quiet="true"/>
</target>
<target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
<echo level="warn" message="Cycle detected: twitter_techsupportgore_bot was already built"/>
<echo level="warn" message="Cycle detected: TwitterTechSupportGoreBot was already built"/>
</target>
<target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
<mkdir dir="${build.dir}"/>

View File

@ -3,6 +3,6 @@ build.xml.script.CRC32=9d82390b
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=3d50692e
nbproject/build-impl.xml.script.CRC32=e587a8e5
nbproject/build-impl.xml.data.CRC32=3680b253
nbproject/build-impl.xml.script.CRC32=ee04fc0e
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

View File

@ -32,6 +32,7 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
/**
* Singleton Hypervisor. This is the object that does everything. So we want it
@ -84,7 +85,7 @@ public class Hypervisor {
/**
* Connection to the SQLITE database.
*/
private final Connection connexion;
private Connection connexion;
/**
* RedditExtractor.
@ -108,13 +109,15 @@ public class Hypervisor {
this.workingDirectory = reader.getProperties("working_directory");
setupTheBotDirectory();
this.connexion = DriverManager.getConnection("jdbc:sqlite:"
+ this.workingDirectory + File.separator + this.sqliteDatabase);
+ this.workingDirectory + File.separator
+ this.sqliteDatabase);
this.myRedditExtractor = new RedditExtractor(subreddit);
if ("Y".equals(reader.getProperties("clear_database"))) {
clearDatabase();
}
this.maxLength = Integer.valueOf(reader.getProperties("max_text_length"));
load();
this.connexion.close();
System.out.println("[+] Hypervisor created successfully.");
}
@ -152,13 +155,16 @@ public class Hypervisor {
InterruptedException {
System.out.println("[+] Hypervisor is now running.");
for (;;) {
this.connexion = DriverManager.getConnection("jdbc:sqlite:"
+ this.workingDirectory + File.separator
+ this.sqliteDatabase);
for (RedditPost post : myRedditExtractor.getRedditPosts()) {
computeRedditPost(post);
}
System.out.println("[*] Cleaning memory.");
System.gc();
this.connexion.close();
System.out.println(
"[*] Hypervisor is waiting for " + this.delay + " seconds.");
"[*] Hypervisor is waiting for "
+ this.delay + " seconds.");
Thread.sleep(this.delay * 1000);
}
}