Reputation: 31
I have homework assignment and the limit of memory is 64 MB and my code uses 68 MB.
I already set my arrays to null and ran Runtime.getRuntime().gc();
Is there anything i can do? Delete all stuff from memory that i don't need? How?
I have 3 int arrays and 3 float arrays, 2 double arrays all of the same N given size.
a = null;
size = null;
prize = null;
required = null;
b= null;
potr= null;
result = null;
Runtime.getRuntime().gc();
Upvotes: 0
Views: 326
Reputation: 7290
First, check whether your program really won't run with 64 MB, using the command-line option -Xmx64m
(exact syntax might depend on your JRE version). You only have a problem if you get an OutOfMemoryError
under that setting.
If Java runs without a command-line limit, it tends to grab more memory than strictly necessary. So I guess, if you see 68 MB in Windows Task Manager or equivalent, everything will be OK.
If you really run into an OutOfMemoryError
, you can try to profile your application. At our company, we're using the commercial JProfiler, a tool that can give you detailed information on memory usage. But it takes a learning curve to understand the profiling results.
An alternative is to post the complete code here or at https://codereview.stackexchange.com/, so we can give more specific help.
Upvotes: 3
Reputation: 89
what all external libraries your code refers.....? jvm loads all classes in memory before execution....if you remove unnecessary imports and libraries that will reduce your memory footprint ...also you can use earlier version of jvm with less features if it satisfies your requirement .hope that helps .
Upvotes: -1
Reputation: 147164
Presumably it is code that is taking the bulk of the memory up. Make use of fewer obscure libraries classes. Or get hold of JDK 1.00.
Upvotes: -1