News:

Pretty crazy that we're closer to 2030, than we are 2005. Where did the time go!

Main Menu

Garbage Collector

Started by Lance, August 04, 2008, 04:43:39 PM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

Lance

I am looking for a way to make my huge JavaOP2 plugin (and JavaOP2 overall, without modifying source) more efficient. I do not know exactly how the Garbage Collector works and when to invoke it. Can someone shed some light on this for me? Thanks.
Quote from: Joe
[23:55:31] [william@enterprise ~/Documents/Programming/javaop2]$ svn commit -m 'Tried to fix StayConnected. Again.'
Committed revision 63.
StayConnected strikes back!

iago

The garbage collector deletes objects that have no references to them. It should invoke itself on a regular basis, you probably don't need to invoke it.

To make your object get garbage collected, just delete any reference to it. As in, set the object to null, make sure it isn't in any lists, etc.

Lance

Ah, thats how I usually unset my variables.

Thanks!
Quote from: Joe
[23:55:31] [william@enterprise ~/Documents/Programming/javaop2]$ svn commit -m 'Tried to fix StayConnected. Again.'
Committed revision 63.
StayConnected strikes back!

Chavo

Out of curiosity, what criteria are you using to decide JavaOp needs to be more efficient?  I ask because you wouldn't be the first person to mistake flood protection for program slowness.

Warrior

The point of a GC is to take the stress of resource management largely off of the user.
Objects are released when a) You exit their scope, b) All references are removed or c) (not sure if this is possible in Java) explicitly invoke the GC.
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Chavo

This article provides an excellent read if you are interested in how the java GC works and optimizing it:

http://www.ibm.com/developerworks/java/library/j-jtp01274.html

However, it's an old article and I don't know how much of it pertains to more recent java verisons.

Camel

Quote from: Warrior on August 05, 2008, 12:11:13 AM
The point of a GC is to take the stress of resource management largely off of the user.
Objects are released when a) You exit their scope, b) All references are removed or c) (not sure if this is possible in Java) explicitly invoke the GC.

Not exactly. Firstly, A is just a special case of B. Secondly, C doesn't allow you to destroy a strongly referenced object. Lastly, that list is incomplete: there are four levels of reference strength:
* Phantom
* Weak
* Soft
* Strong

If there were only strong references, your B would be the only reason an object could become a candidate for GC. A strong reference is a direct reference; given:
Object o = new Object();
o is a strong reference to the new object, and that object can therefore not be a candidate for GC until o's scope closes, or possibly longer if the object becomes referenced by anything else.

Then you have 3 classes that built off of Refrence. Think of the reference class as such:
public abstract class Reference<T> {
    T ref;

    public Reference<T>(T ref) {
        this.ref = ref;
    }

    public T get() {
        return ref;
    }
}


The phantom reference never stores a copy of the object:
public class PhantomReference<T> extends Reference<T> {
    public PhantomReference<T>(T ref) {
        super(null);
    }
}


Then you have soft/weak references, which behave out of the ordinary with regards to the GC. These two types of references are only guaranteed to reference an object for as long as that object is strongly reachable. In the case of a weak reference, the object will be destroyed upon the first GC cycle. In the case of a soft reference, the GC will try to keep it around until it runs out of memory.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Lance

Quote from: Chavo on August 04, 2008, 08:20:16 PM
Out of curiosity, what criteria are you using to decide JavaOp needs to be more efficient?  I ask because you wouldn't be the first person to mistake flood protection for program slowness.

I want to lower the amount of memory JavaOP2 uses since it is temporarily on a low-memory windows system.
Quote from: Joe
[23:55:31] [william@enterprise ~/Documents/Programming/javaop2]$ svn commit -m 'Tried to fix StayConnected. Again.'
Committed revision 63.
StayConnected strikes back!

Chavo

Turn off the GUI Plugin then :)

Lance

Quote from: Chavo on August 12, 2008, 12:36:39 AM
Turn off the GUI Plugin then :)

For some reason, JavaOP2 is using more memory without the GUI plugin :(
Quote from: Joe
[23:55:31] [william@enterprise ~/Documents/Programming/javaop2]$ svn commit -m 'Tried to fix StayConnected. Again.'
Committed revision 63.
StayConnected strikes back!

Camel

You are probably using the Server GC profile. Add -client to the java command line.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Lance

I have more memory available now, so never mind. Thanks for all the help  :)
Quote from: Joe
[23:55:31] [william@enterprise ~/Documents/Programming/javaop2]$ svn commit -m 'Tried to fix StayConnected. Again.'
Committed revision 63.
StayConnected strikes back!