Valkyr Posted February 17, 2015 Share Posted February 17, 2015 (edited) 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. Edited February 17, 2015 by Valkyr Quote Link to comment Share on other sites More sharing options...
Jack Posted February 17, 2015 Share Posted February 17, 2015 Quote Link to comment Share on other sites More sharing options...
Joseph Posted February 17, 2015 Share Posted February 17, 2015 Note: Don't actually use this, I posted it as a joke because I'm bored. then why is it under the snippet section lol Quote Link to comment Share on other sites More sharing options...
Valkyr Posted February 17, 2015 Author Share Posted February 17, 2015 then why is it under the snippet section lol Its an old snippet I found lying around from when I was trolling rune-server :P I guess a mod could move it to spam/off-topic Quote Link to comment Share on other sites More sharing options...
Mysteryy Posted February 17, 2015 Share Posted February 17, 2015 The ArrayList of* GarbageCollectors are like an army which get sent back in time to* destroy the garbage before it's able to harm. 1 Quote Link to comment Share on other sites More sharing options...