Results 1 to 11 of 11
  1. #1
    vasavi.singh is offline Member
    Join Date
    Feb 2009
    Posts
    24
    Rep Power
    0

    Default Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

    Hi,

    I have a small doubt that by adding an variable of type 2-dimensional array it is giving the OutOfMemoryError. In my code I am using almost using the arrays. By continuing this process after adding a one more 2-dim array variable it is giving the above error. How it could be and How can I solve this problem.

    Java Code:
    public class SocialNetworkCons
    {
            CommunicationNetworkId[] networkIds = { new CommunicationNetworkId("Academics") };
            AcademicsAgents agent[]=new AcademicsAgents[500];
            Author author[]=new Author[1000];
            ReadingInput input=new ReadingInput();
    
            static int m=0,n=0,j;
            int p,r,temp,authorId,articleId=-1;
            int neighborsList[][]=new int[1000][1000];
            int weightBetweenAuthors[][]=new int[1000][1000];
            float weightBetweenAuthorNArticle[][]=new float[1000][1000];
            int edgeBetweenAuthorNArticle[][]=new int[1000][1000];
            int authorsId[]=new int [20];
            float threshold[]=new float[5000];
            ArrayList Hits = new ArrayList();
            int noOfAuthors=-1;
            float refEdge[][]=new float[1000][1000];
          int coAuthors[][]=new int[1000][1000];  // by simply including this variable it is giving OutOfMemoryError.
     
          ............
           .........  // some code
    }
    Regards,
    vasavi

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    What's the purpose of using this much of arrays in your application? Even Java follows automatic garbage collection, no wonder there could be a memory leak anyway.

  3. #3
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    As said in the last post its a memory leak situation or it requires more than the default memory 128 mb, so you might want to increase the heap space.

    Increase heap size in Java to prevent java.lang.OutOfMemoryError

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by dswastik View Post
    As said in the last post its a memory leak situation or it requires more than the default memory 128 mb, so you might want to increase the heap space.

    Increase heap size in Java to prevent java.lang.OutOfMemoryError
    Yes it is. But it' also better if we can write our code much safer way. Actually because of the garbage collector in Java, we always safe. Use of the best way is better than that. ;)

  5. #5
    vasavi.singh is offline Member
    Join Date
    Feb 2009
    Posts
    24
    Rep Power
    0

    Unhappy Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

    Hi friends,

    Thank You for your valuable suggestions. I am a PG student doing the project in final year. My application (project) has to create a large network having many nodes and establishing the connections between the nodes dynamically both nodes as well as edges between them. I am new to java. So I took the help of arrays. The number of nodes are unknown to us initially that's why I created a large size of arrays. That was the reason for creating the arrays of size 1000.

    By viewing previous post I found that, if there is no more memory to create new objects then JVM throws an exception. I will explain the application what I am doing.

    I have to store a new article information and as well as its author Information. For that I created an array of objects of size 500 and 1000 respectively (we don't know the count of articles and authors initially). Constructing a network based on the data which is stored in a file. And passing this network to different methods to see the results. It is working well using console. I am trying it to convert a GUI.

    Main.java is a file in which I am creating an object for the homepage.java and calling it. From there I kept a ok and cancel button. On pressing ok button it has to go to other window in which article information has to enter. Again on validating the information it has to accept the author information (it may be 1 or more than one it depends on the data entered by a user). All this information is stored in a file (acts as a database). Using the data stored in a file the other method in a java program creates a network and passing it to different methods. Till know it is working well. I would like to consider some other criterias and checking how this methods are working. For that I created an arrays coAuthors of size 1000X1000. Just by creating an array it is giving the OutOfmemory exception before adding this variable it is working well.

    Coming to objects all are interlinked. Because on clicking ok only it has to goto other window. Up to my knowledge there is no way to call the methods in Main.java on clicking the ok button. In my aspect all object are in the active state. Now also I am not trying to create new objects. Why this exception is raised I am not getting the point.

    I also tried to increase the heapsize it is giving the invalid initial size and max size. I am using Linux platform. I don't know how to get the initial heap size and upto what extend i can increase the size.

    I used the command java -Xms32mb -Xms128mb
    The error it is giving is Invalid initial heap size: -Xms32mb
    Could not create the Java virtual machine.

    Please respond fast.

    Regards,
    vasavi

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  7. #7
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    If you don't know how big your arrays will be, use Vectors or other Collections in java.util. They will automatically grow to accommodate new elements.

    It's probably better to keep information in persistant storage - files or even better an actual database - and only load it into memory when you actually need it.

    If you do these you probably won't run out of memory.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  8. #8
    2potatocakes is offline Member
    Join Date
    Sep 2008
    Posts
    43
    Rep Power
    0

    Default

    Hi mate,

    I too have written a program that requires the use of very large arrays and I ran into the same problem. Don't know if this post has been solved yet but I increased my java heap size considerably and just used

    -Xms128m -Xmx1024m

    Using 32 and 128 as your min and max doesn't seem large enough.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by OrangeDog View Post
    It's probably better to keep information in persistant storage - files or even better an actual database - and only load it into memory when you actually need it.
    I vote for this lol. Rather handling such instance in the program, best thing is record data and referring them when you want. Much better if you can work on with databases, than the files.

  10. #10
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    You give your app a max of 1GB, 2potatocakes? xD that's one hell of an application then. ;)
    I die a little on the inside...
    Every time I get shot.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 2
    Last Post: 12-14-2009, 01:46 AM
  2. Replies: 10
    Last Post: 01-29-2009, 08:00 AM
  3. Replies: 16
    Last Post: 07-24-2008, 11:45 AM
  4. Replies: 14
    Last Post: 06-12-2008, 08:36 AM
  5. Replies: 3
    Last Post: 01-29-2008, 01:37 AM

Posting Permissions

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