Thread: What is '-Xmx1024m'? Why is it needed, ect.

Page 1 of 3 123 LastLast
Results 1 to 10 of 25
  1. #1 What is '-Xmx1024m'? Why is it needed, ect. 
    Registered Member
    Join Date
    Oct 2007
    Posts
    2,420
    Thanks given
    259
    Thanks received
    479
    Rep Power
    2759
    In each Java application, there is a set amount of heap (also know as memory) the application can use. This is very important because memory is used by how many objects are allocated in the application. The more objects stored in the memory, the more memory you will need to give the application.

    Most people think, the more memory you shove into a application the better it runs and what not. This is only somewhat true, because of the way most of all Runescape Private Servers are built. If the server is a memory hog and isn't programmed correctly, like most servers are, it will have a memory leak causing it to eat lots of heap, thus making it crash eventually, that's why people think that giving more heap to the application fixes problems. Honestly, it fixes nothing, it just covers up the problem.

    When making a server, you want to make sure there are no memory leaks that will eat all the heap. To do this you want to run benchmarks and profiler tests to see what's using the most amount of heap and then go see what's wrong, if there is anything wrong.

    Now a normal server, if writen correctly should only have the use around 2048mb of memory. This is plenty of memory to store data, and what not. If you want to take full advantage of your heap, you should store lists of things, such as NPC, Object, Player data inside the heap, for fast access and less CPU power. Doing so will result in more heap used, because you're storing lots of data in the memory, this isn't a bad thing, because if it's all writen properly it will allow you to retrieve data faster.

    Thanks for reading, hope you learned something.

    Here is a great post by Graham, explaining what a Memory Leak is:

    Quote Originally Posted by Graham View Post
    No, it means the programmer has not released all references to the object.

    Say for instance I made a class like this:

    Code:
    public class VeryLargeObject {
        public byte[] lotsOfData = new byte[10241024];
    }
    And then another class that did something with them:

    Code:
    public TestClass {
        public VeryLargeObject[] objects = new VeryLargeObject[10];
    
        public TestClass() {
            for(int i = 0; i < objects.length; i++) objects[i] = new VeryLargeObject();
        }
    }
    And then wrote a piece of code like this:

    Code:
    public static void main(String[] args) throws InterruptedException {
        TestClass test = new TestClass();
        while(true) {
            // doing something with TestClass to ensure it doesn't get optimized away
            System.out.println(test.getClass());
            Thread.sleep(10000L);
        }
    }
    Because there are still references to the object, the garbage collector will not delete it and it will take up memory.

    The garbage collector will do its best to delete objects if you need more memory (i.e. when the heap space runs out, and you try to allocate more memory, it'll try to delete unused memory), or when System.gc() is called and I also think it does it on a schedule in most VMs.

    However, the problem Gnarly is talking about, is where you accidently leave references to an object. Like in the example above, the objects array could still be accessed, so the garbage collector does not delete it and it sits there taking a lot of memory.

    You can ensure this doesn't happening by setting references to an object to null where appropriate. However *this does not need to be done all the time* (and some code here does it too much).

    For instance, say you had this method:

    Code:
    public void doSomething() {
        Object o = new Object();
        // now do some stuff
    }
    You do not need to set o to null at the end, because the reference is lost when the method exists anyway.

    The same goes for a class like this:

    Code:
    public class MyClass {
         public Object someObject = new Object();
    }
    If you had some code that used it like this:

    Code:
    MyClass class = new MyClass();
    // now do something
    At the end many people here would write

    Code:
    class.someObject = null;
    class = null;
    However, in this case, it is not necessary and you just need to do

    Code:
    class = null;
    What you do need to be wary of is:

    - references of an object in others that are not going to be garbage collected
    - references of an object in collections in other classes/instances of that class - needs to be removed from the collection otherwise a reference remains and it will not be garbage collected.
    - probably more situations, you just get to know the best way of doing this with experience.
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member

    Join Date
    Jan 2008
    Age
    21
    Posts
    1,387
    Thanks given
    76
    Thanks received
    385
    Rep Power
    962
    Thanks bro.
    Reply With Quote  
     

  4. #3  
    Registered Member
    Pilldom's Avatar
    Join Date
    Sep 2007
    Posts
    1,246
    Thanks given
    22
    Thanks received
    206
    Rep Power
    156
    Haha nice.
    Reply With Quote  
     

  5. #4  
    Banned

    Join Date
    May 2008
    Posts
    2,327
    Thanks given
    55
    Thanks received
    67
    Rep Power
    0
    this is how i learned about it


    higher = more cpu usage && more stability
    thats what i learned b4 this
    after this, im just clueless cuz i didn't rely understand much of this
    Reply With Quote  
     

  6. #5  
    Registered Member
    Join Date
    Oct 2007
    Posts
    2,420
    Thanks given
    259
    Thanks received
    479
    Rep Power
    2759
    Quote Originally Posted by silabgarza View Post
    this is how i learned about it


    higher = more cpu usage && more stability
    thats what i learned b4 this
    after this, im just clueless cuz i didn't rely understand much of this
    The more heap you give to a application doesn't increase the CPU usage, and the only reason it makes servers more stable is because they have memory leaks. That means they eat lots of memory/heap and make it crash after there is no more available heap. By shoving more heap into the server, it allows it to eat more heap, thus making it last longer before it crashes. So really it doesn't make the server more stable, it just makes it last longer before it crashes. Shoving more heap into a server fixes nothing, all it does is cover up the problem.
    Reply With Quote  
     

  7. #6  
    I'm smarter then you

    Mister Maggot's Avatar
    Join Date
    Dec 2008
    Age
    18
    Posts
    7,112
    Thanks given
    3,260
    Thanks received
    2,875
    Rep Power
    5000
    What is a memory leak?
    Quote Originally Posted by Original View Post
    Yeah, I haven't used JFrame before, I've always used OpenGL
    Quote Originally Posted by Harlan View Post
    well c++ compiler is annoying as heck and can't be trusted
    I coded a boolean once
    \_(ツ)_/ lol idk just rep me
    Behemoth RSPS: [Only registered and activated users can see links. ] i have no idea what i am doing
    66.176.193.75 -- Hack me; I triple dog dare you.
    [Today 11:29 PM] MOB KLICK: Syria would blow the USA to pieces that's why you didn't evade
    Reply With Quote  
     

  8. #7  
    Registered Member
    Join Date
    Oct 2007
    Posts
    2,420
    Thanks given
    259
    Thanks received
    479
    Rep Power
    2759
    Quote Originally Posted by i r maggot View Post
    What is a memory leak?
    When a certain point/thing in the application keeps taking memory and not releasing it after a certain point.
    Reply With Quote  
     

  9. #8  
    I'm smarter then you

    Mister Maggot's Avatar
    Join Date
    Dec 2008
    Age
    18
    Posts
    7,112
    Thanks given
    3,260
    Thanks received
    2,875
    Rep Power
    5000
    Example?

    Sorry :P
    Quote Originally Posted by Original View Post
    Yeah, I haven't used JFrame before, I've always used OpenGL
    Quote Originally Posted by Harlan View Post
    well c++ compiler is annoying as heck and can't be trusted
    I coded a boolean once
    \_(ツ)_/ lol idk just rep me
    Behemoth RSPS: [Only registered and activated users can see links. ] i have no idea what i am doing
    66.176.193.75 -- Hack me; I triple dog dare you.
    [Today 11:29 PM] MOB KLICK: Syria would blow the USA to pieces that's why you didn't evade
    Reply With Quote  
     

  10. #9  
    Registered Member
    Pilldom's Avatar
    Join Date
    Sep 2007
    Posts
    1,246
    Thanks given
    22
    Thanks received
    206
    Rep Power
    156
    What kind of tests can we do to find memory leaks?
    Reply With Quote  
     

  11. #10  
    Seecon
    Guest
    Quote Originally Posted by Gnarly View Post
    When a certain point/thing in the application keeps taking memory and not releasing it after a certain point.
    Does this involve the Garbage Collector not cleaning up or what?
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •