DeathfireD / AllianceP2P

Alliance takes the best from BitTorrent, Direct Connect and Waste and creates a decentralized and secure p2p network. It is a private and secure environment to share files and communicate with people you know. Alliance works on Windows, Linux and Mac.
12 stars 8 forks source link

Remove explicit GC calls #13

Open abonander opened 11 years ago

abonander commented 11 years ago

I was looking through some of the code (I was looking for the entry point of the program so I could start building a mental map of the execution), and I found what I was taught is a Java no-no in org.alliance.launchers.console.Console:

private void gc() {
        System.gc();
        System.gc();
        long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
        printer.println("Garbage collected. Using " + TextUtils.formatNumber("" + used) + " bytes of memory.");
    }

Explicit calls to System.gc(), and a convenience method to attempt to force garbage collection by calling for it twice. I don't see any reason for usage of this in the current state of Java and this extra method call might actually be adding more overhead than it saves by invoking garbage collection.

I'm going to make this my first task on this project. It's simple refactoring, but I think it needs to be done.

DeathfireD commented 11 years ago

I can't remember the reason for why that was added (if there was even a reason at all). I'll try contacting Bastvera (one of the previous programmers who did the bulk of Alliance's coding).

I think a refactoring would be a great idea. The majority of that code is so out dated and untouched I'm sure you'll find some stuff like above that could be done a better way. Feel free to tackle that task.

Bastvera commented 11 years ago

That method is a part of Console functionality, you simply put 'gc' in Alliance Console and it will execute that Method. It is NOT (and it shouldn't be) part of normal program flow. This is something old, made by original author, probably to VERY simply check memory usage because at the time when Alliance were created Debugging was not so fancy and powerful like is today. The best would be to remove this method completely.

DeathfireD commented 11 years ago

FYI. Bastvera is one of the major contributors to Alliance that no longer has time to actually code anymore. He'll be answering questions on here every so often.