I have an applet that checks a website for updates, it does so by loading the website's HTML into a String object, then searching that String for a pattern, however because the website takes a considerable amount of space I'm already noticing that the App is growing in its memory usage with every scan. I assume this is because rather than rewriting the contents of the old string it is creating a new one and doing I don't know what with the old one, but not deleting it.
Here's the code I wrote
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Scanner;
/**
* Created by zaers on 15-Apr-16.
*/
public class PageSearch {
public static void main(String[] args){
while(true) {
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
System.exit(1); //OS screwed our program
}
try {
String out = new Scanner(new URL("http://blog.dota2.com/").openStream(), "UTF-8").useDelimiter("\\A").next();
if(out.contains("6.87")){
java.awt.Desktop.getDesktop().browse(new URI("http://www.youtube.com/watch?v=-kcOpyM9cBg&t=7m21s"));
break;
}
else continue;
} catch (IOException e) {
System.exit(2); //Blog is kill
} catch (URISyntaxException e) {
System.exit(3); //YouTube is kill
}
}
}
}
I noticed this because on first run the app takes 8.5mb, however it is currently at 27.8 and growing with every check.