|
| |||||||||
| Tags: array, heap, memory, memory allocation, memory heap |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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];
__________________ www.techarena.in |
|
#2
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| Re: Memory error in java
Hello, When you make a Code: s = new String [50] [500] [50] |
|
#5
| |||
| |||
| 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
| |||
| |||
| 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;
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Memory error in java" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 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 01: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 05:31 PM |
| SBSMonitoring/SQL Memory allocation error (run away Memory usage) | David Gill | Small Business Server | 1 | 21-09-2005 12:32 PM |