Jump to content

Is your script using too much RAM? Here's the SOLUTION


Recommended Posts

Posted (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 by Valkyr

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...