Results 1 to 6 of 6

Thread: Memory error in java

  1. #1
    Join Date
    Mar 2010
    Posts
    222

    Memory error in java

    Hello,
    I have an interest in my application because when I compile a number of times I have a message like java.lang.OutOfMemeryError. Instead of reallocating memory I'd like to know where have the problem.
    In my class I declare an array (global variable) type
    Code:
    static String s [][][] = new String [50] [500] [50];
    then I have a function that reads a file and calls a function that processes the lines of this file. In this function I assign values to my table. So, do you have a solution for this, if yes then I am interested. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    347

    Re: Memory error in java

    Hello,
    To reset your picture, you should rather make:
    "stab = null;" => this indicates clearly the garbage collector that can destroy the object to recover his memory. Then, if you're just reading data in your files, and you have several identical strings (which is certainly the case given the volume of data), you should call the method "intern ()" on Your String before storing in your array. You earn a lot of room occupancy memory. Hope this will help you.

  3. #3
    Join Date
    Nov 2009
    Posts
    518

    Re: Memory error in java

    Hello,
    You really need a 3-dimensional array of this size?
    Your table is 50 * 50 * 500 or 1,250,000 of strings.
    So:

    1) it is not surprising that you had an OutOfMemory (the method "intern ()" I've suggested above should help you greatly: it allows you to use the same object for strings identical, and thus avoid unnecessary duplication of voluminous data in memory)

    2) you have certainly a design problem at the base of your application.

  4. #4
    Join Date
    Nov 2009
    Posts
    446

    Re: Memory error in java

    Hello,
    When you make a
    Code:
    s = new String [50] [500] [50]
    a new memory space is allocated. The other area has more reference, but the time that the gc runs behind, the memory space. Before re-initialize your table, make a stab = null. You can explicitly call the garbage collector by Runtime.getRuntime().Gc(), but this method is used only in critical cases.

  5. #5
    Join Date
    Nov 2009
    Posts
    330

    Re: Memory error in java

    Hello,
    I completely agree with the above post and I would like to add some more to it. It is up to you if you really need to store all the strings. If you over-sizing your table to make sure you have enough space, even when it allocates memory space even if your table is empty. Used instead dynamic collections like ArrayList. Hope this helps you and you solve your problem very soon. Best of Luck

  6. #6
    Join Date
    Nov 2009
    Posts
    583

    Re: Memory error in java

    Hello,
    Have a look at the following example, this may help you
    Code:
    Public static String display(String[][][] s){
      String str = "";
      for(int a = 0; I <s.length; I + +){
        for(int b = 0J <s[a].lengthJ + +){
          for(int c = 0K <s[a][b].lengthK + +){
            str + = s[a][b][c] + "\ n";
        }
      }
      return str;
    }

Similar Threads

  1. Memory error 0x0237a33c in Firefox 12, Java outdated & disabled
    By Oye! Champion in forum Technology & Internet
    Replies: 4
    Last Post: 29-04-2012, 03:22 PM
  2. Detect memory leak in java
    By Isabella in forum Software Development
    Replies: 8
    Last Post: 14-11-2011, 11:56 AM
  3. java- store a web page in memory
    By arvindikchari in forum Software Development
    Replies: 1
    Last Post: 15-06-2011, 12:19 AM
  4. Access memory address in java
    By Kingfisher in forum Software Development
    Replies: 5
    Last Post: 15-01-2010, 02:40 PM
  5. Distribution of the Java memory
    By Sandy22 in forum Software Development
    Replies: 3
    Last Post: 30-10-2009, 04:31 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,581,711.94155 seconds with 17 queries