View RSS Feed


Java Memory

  1. Getting Java Heap Size

    by , 02-18-2012 at 04:29 PM
    In JVM, heap size is considered as a main area. New objects are stored or created here. To get heap size, see this Java code. We will also be considering various memory methods.

    Java Code: This is the code to get the heap size in Java
    // Get current size of heap in bytes
    long heapSize = Runtime.getRuntime().totalMemory();
    // Get maximum size of heap in bytes. The heap cannot grow beyond this size.
    // Any attempt will result in an OutOfMemoryException.
    long heapMaxSize = Runtime.getRuntime().maxMemory();
  2. Understanding Java Memory Settings

    by , 02-18-2012 at 04:28 PM
    -Xmx & -Xms parameters set memory. Here discussion would be done regarding such parameters that why they are used to set memory.

    JVM i.e. Java Virtual Machine is produced in system memory, when Java starts. Execution as well as complete process of Java program occurs in JVM. Java applications have 64MB memory, by default.

    In JVM, Xms is minimum heap size. If high sized initial memory is set, this might help a lot. Like,

    • GC would be made to work
    Tags: java memory Add / Edit Tags
  3. Java Garbage Collection

    by , 02-18-2012 at 04:26 PM
    Java provides support for its memory management by using its built-in mechanism. In Garbage collector, two threads run.

    Responsibility of 1st thread is memory collections, primarily heap. It is quite light weighted.
    2nd thread is considered to be a full GC thread. When comes memory shortage, entire heap is
    traversed by it. Spaces for the objects are allocated by it.

    When there is inadequate heap allocation or memory leak then full GC thread runs ...
  4. How to manage Java Heap Size?

    by , 02-18-2012 at 04:25 PM
    You can specify the memory allocation for JVM using X option. Following table explains the JVM options.

    -Xms: initial java heap size
    -Xmx: maximum java heap size
    -Xmn: the size of the heap for the young generation

    unix> bin/ -Xmn100M -Xms500M -Xmx500M
    win> bin/httpd.exe -Xmn100M -Xms500M -Xmx500M
    install win service> bin/httpd.exe -Xmn100M -Xms500M -Xmx500M -install

    To set max Xmx and min Xms heap sizes ...
  5. Java memory management

    by , 02-18-2012 at 04:22 PM
    There are 2 categories of Java memory management problems which are as following:

    1. In-complete deallocation
    2. Pre-mature deallocation

    Incomplete deallocation has been divided into 2 subclasses which are:

    1. Desing bugs
    2. Coding bugs

    Coding bugs are considered to be dependent upon language whereas design bugs are not language dependent. They are programming mistakes. Usually programmer is involved in handling the memory ...
  6. Minimize memory leaks in Java

    by , 01-08-2012 at 01:46 PM
    The main causes for memory leaks in java are poor design with invalid references. Garbage collector is not able to claim those objects.

    Following steps help you to detect memory leaks in your application.

    Use tools like JProbe, OptimizeIt.
    Use operating system process monitors.
    Override totalMemory() and freeMemory() methods in the Java Runtime class.

    Following steps help you to minimize memory leaks in your application.
  7. Unnecessary Object Creation with Immutable Objects

    by , 11-30-2011 at 12:05 AM
    Programmers are often not aware of how to create objects that can be reused. The key to understanding how to create reusable objects is that they must be immutable. So for example if you a running a loop in which each loop a string instance is required, rather than create a new instance every time it executes, you simply reuse the existing instance.

    Rather than create a new String instance.

    Java Code:
    public void BuildingLoop{
    	int total = 10;
    	for(int i=0;
  8. Unnecessary Object Creation with Mutable Objects

    by , 11-29-2011 at 11:59 PM
    Continuing with our last tip on immutable objects, we now look at re-using mutable objects. Although you cannot modify a mutable object, you can avoid unnecessarily waste memory by reusing the existing instance. So consider for example mutable Date objects. Once the values are computed, they are never modified. So for example if you a running a loop in which each loop a string instance is required, rather than create a new instance every time it executes, you simply reuse the existing instance. ...