Jump to content

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


Valkyr

Recommended Posts

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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