So I noticed one of my scripts was using stupid amounts of RAM, but at the cost of a little CPU usage, I solved it! I present to you... *drumroll*
THE ULTIMATE GARBAGE COLLECTOR
/*
* @author: Valkyr
*
* This class is a replacement for the default JVM garbage collection.
* The factory of GarbageCollectors is used to
* create a constant flow of garbage collection. The ArrayList of
* GarbageCollectors are like an army which get sent back in time to
* destroy the garbage before it's able to harm.
*
*/
import java.util.ArrayList;
import java.util.Iterator;
public class GarbageCollector {
static ArrayList<GarbageCollector> collectors = new ArrayList<GarbageCollector>();
public GarbageCollector() {
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
GarbageCollector.collectors.add(new GarbageCollector()); // Creates a new GarbageCollector
Iterator<GarbageCollector> it = collectors.iterator();
while (it.hasNext()) {
GarbageCollector gc = it.next(); // Assign's the GarbageCollector's role
try {
Thread.sleep(-1); // Sends the GarbageCollector back in time
} catch (InterruptedException e) {
e.printStackTrace();
}
((GC) gc.getGet().getGC().get().getGet()).gc(); // Activate's the GarbageCollector's internal hardware and eradicates the garbage
}
}
}
}).start();
}
public GarbageCollector getGet() {
return new GarbageCollector();
}
public GC getGC() {
return new GC();
}
public static class GC extends GarbageCollector {
/*
* The GC. Core of every GarbageCollector. It is vital to fight and defend against the garbage.
*/
public GC getGet() {
return new GC();
}
public GarbageCollector get() {
return new GarbageCollector();
}
public void gc() {
Runtime.getRuntime().gc(); // Destroys the garbage.
}
}
}
Note: Don't actually use this, I posted it as a joke because I'm bored.