Results 1 to 3 of 3
Thread: Low memory error
- 02-08-2008, 03:33 PM #1
Member
- Join Date
- Feb 2008
- Posts
- 2
- Rep Power
- 0
Low memory error
When I run an application (this one creates a site map) I was getting a low memory error. So to increase the java memory, I went to the java console and entered -Xmx128m. Still getting the error I increased the memory size up to 185. Still get the low memory error. When I enter a value of -Xmx190 or higher, I get something like "can't run/start java environment" when I run the application.
What is my problem and how can I fix it. I have 1Gb ram on this computer. This is the newest java download.
- 02-08-2008, 09:51 PM #2
Welcome, rlhs76, to Java Forums!
It is true that the Java Virtual Machine does memory management automatically, but it does so in its own time. If you write an application that uses memory heavily, you might want to free it as soon as you can to prevent the "out of memory" exception. My solution to this is to force garbage collection. You must also make sure that objects that are to be deleted are not referenced. Here is an interesting program that demonstrates my point:
I've attached some output for this program in text files. You can see the difference between using memory management (Good.txt) and not (Bad.txt). :eek:Java Code:package pack; import java.util.*; public class Test{ private Vector<Vector<Byte>> junk; public static void printMemory(){ Runtime runtime = Runtime.getRuntime(); System.out.println("Free memory = " + runtime.freeMemory()); System.out.println("Total memory = " + runtime.totalMemory()); } public static Vector<Byte> createJunk(int bytes){ Vector<Byte> result = new Vector<Byte>(); for (int i = 0; i < bytes; i++){ result.add(new Byte((byte)255)); } return result; } public Test(){ System.out.println("This program demonstrates memory management in java."); System.out.print("Enter the number of runs: "); int runs = Integer.parseInt(readln()); System.out.print("Use memory management (Y/N): "); boolean manageMemory = readln().toLowerCase().equals("y"); System.out.print("Enter the number bytes for each peace of junk: "); int junkSize = Integer.parseInt(readln()); run(runs, manageMemory, junkSize); } public void run(int count, boolean manageMemory, int junkSize){ try{ junk = new Vector<Vector<Byte>>(); System.out.println("Running with memory management = " + manageMemory + " :\n"); Runtime runtime = Runtime.getRuntime(); for (int i = 1; i <= count; i++){ System.out.println("run = " + i); printMemory(); System.out.println("creating junk"); Vector<Byte> someData = createJunk(junkSize); printMemory(); if (manageMemory){ try{ System.out.println("collecting"); someData = null; runtime.gc(); System.out.println("done collecting"); printMemory(); } catch (Throwable e){ showError(e); } } else { junk.add(someData); } System.out.println(); } } catch (Throwable e){ showError(e); } } public static void showError(Throwable e){ StackTraceElement[] stack = e.getStackTrace(); String stackOut = new String(); int number = 0; for (StackTraceElement element : stack) { number++; stackOut += number + "\n" + " Method: " + element.getMethodName() + "\n" + " Class: " + element.getClassName() + "\n" + " Line: " + element.getLineNumber() + "\n"; } String message = "The following problem has accured:" + "\n\n" + "Name: \n" + e.getClass().getName() + "\n\n" + "Message: \n" + e.getMessage() + "\n\n" + "Cause: \n" + (e.getCause() != null ? e.getCause().toString() : "unknown") + "\n\n" + "Stack trace: \n" + stackOut; System.out.println(message); } public static String readln(){ Scanner scanner = new Scanner(System.in); return scanner.nextLine(); } public static void main(String[] arg){ Test test = new Test(); System.out.println("Program finnished"); readln(); } }
I hope this will help you. ;)Eyes dwelling into the past are blind to what lies in the future. Step carefully.
- 02-08-2008, 10:25 PM #3
Member
- Join Date
- Feb 2008
- Posts
- 2
- Rep Power
- 0
I don't write java code. I'm just a user. I have 3 pc's at home and they all have the same issue, when I increase java memory with the commmand -Xmx190m java will not load as I get a "can't load java environment" error. Maybe I posted my question in the wrong location. But I would really like to fix the problem. The application I'm running is a sitemap generator. Feel free to try it and see if it works for you. I'm running it from Firewall Test, Web Tools and Free Internet Security Audit Select the sitemap generator and generate a map from a large site. You can use mine if you like STUFF U NEED
Similar Threads
-
Out of memory
By mew in forum New To JavaReplies: 1Last Post: 01-20-2008, 08:55 AM -
Memory
By mew in forum CLDC and MIDPReplies: 0Last Post: 12-28-2007, 11:02 AM -
How to reduce the size or avoiding out of memory error?
By rajeshkumarmsc in forum Advanced JavaReplies: 3Last Post: 08-11-2007, 10:15 PM -
Java Heap Out of Memory Error
By stonkers in forum New To JavaReplies: 3Last Post: 07-17-2007, 04:43 PM -
Consumption of memory
By Daniel in forum Advanced JavaReplies: 1Last Post: 07-06-2007, 09:11 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks