Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Memory error in java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 10-03-2010
Member
 
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.

Reply With Quote
  #2  
Old 10-03-2010
Member
 
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.
Reply With Quote
  #3  
Old 10-03-2010
Member
 
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.
Reply With Quote
  #4  
Old 10-03-2010
Member
 
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.
Reply With Quote
  #5  
Old 10-03-2010
Member
 
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
Reply With Quote
  #6  
Old 10-03-2010
Member
 
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;
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 06:52 AM.