Results 1 to 18 of 18
Thread: Java limitaion
- 08-23-2011, 10:12 PM #1
- 08-23-2011, 10:24 PM #2
- 08-23-2011, 10:28 PM #3
but doesnt heap space have a default value for all computers?
- 08-23-2011, 10:33 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
I believe you can change the amount of heap space. I'd suggest writing an experiment, get a stringbuilder and continuously concatenating random characters to it.
- 08-23-2011, 10:48 PM #5
doing it right now(with a string).
Right now, I am at 17000 characters. I report back when I reach the limit.
- 08-24-2011, 12:47 AM #6
I canceled the execution after the string was 2 million characters long. It was so slow appending character to such a long string.
- 08-24-2011, 01:16 AM #7
I wrote this small program to see how many items I could add to an ArrayList to see how big it could get before I exceeded the amount of memory.
The output is as follows:Java Code:import java.util.ArrayList; public class MemoryLimit { public static void main( String[] args ) { MemoryLimit m = new MemoryLimit(); m.memoryLimit(); } public void memoryLimit() { ArrayList<Character> list = new ArrayList<Character>(); int i = 0; try { while( true ) { list.add( 'a' ); i++; } } catch( OutOfMemoryError e ) { System.out.printf( "Number of one byte characters added to an ArrayList = %d\n", i ); } } }
It seems I was able to add nearly 26 million characters to the ArrayList before running out of memory.Java Code:Number of one byte characters added to an ArrayList = 25764983
The PC I used was a Core 2 Quad machine running Windows XP with 4GB RAM.
I was wondering if someone more knowledgeable about computer or OS memory architecture could explain this.
Thanks.If you aren't programming in Java, well that's just too bad.
I'd rather be using Ubuntu.
- 08-24-2011, 02:35 AM #8
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
I can't vouch for the accuracy, but here is a link which may be helpful: [JavaSpecialists 029] - Determining Memory Usage in Java
- 08-24-2011, 03:33 AM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
The memory tester from that article and the following Object Factory,
produces this:Java Code:import java.util.*; public class ListFactory implements ObjectFactory{ public Object makeObject(){ ArrayList<Character> charList = new ArrayList<Character>(); for(int i = 0; i < 25764982; ++i) charList.add((char)33); return charList; } }
103,059,968Java Code:ListFactory produced java.util.ArrayList which took 103059968 bytes
The problem was that a character takes up more than a byte so using the counter directly as you did will cause some problems.
- 08-24-2011, 03:46 AM #10
I just ran the same program on my Core2Duo laptop running Ubuntu 10.04 64bit with 4GB RAM and I got the following:
Java Code:Number of one byte characters added to an ArrayList = 86956820
If you aren't programming in Java, well that's just too bad.
I'd rather be using Ubuntu.
- 08-24-2011, 10:43 AM #11
Member
- Join Date
- Nov 2010
- Posts
- 15
- Rep Power
- 0
I ran the same problem on my six core amd phenom 2 1055t computer with 6 gigs of ram and I got 25764983 as output.
- 08-24-2011, 12:06 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Maximum heap size is (currently) 1/4 of your physical memory or 1Gb, whichever is smaller.
This can be changed (as said earlier) by using Xmx.
- 08-24-2011, 09:12 PM #13
I wonder do the makers of the JRE set these heap sizes based on OS? The Linux 64 bit OS has a little over 3X the heap space. I don't know what OS Fabken is running, but I would guess Windows 7 64 bit, but I could be wrong.
If you aren't programming in Java, well that's just too bad.
I'd rather be using Ubuntu.
- 08-25-2011, 09:10 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Not according to the documentation...of course it all depends if you are both using Oracle JVMs.
besides, I wouldn't rely on the above code...I'd use the Runtime.maxMemory() method, which will tell you what Xmx is set to, pretty much.
- 08-25-2011, 09:06 PM #15
I ran the following code on my Windows XP machine:
I got the following output:Java Code:public void memoryUsage() { long mem = Runtime.getRuntime().maxMemory(); System.out.printf( "Number of bytes the JRE will attempt to use = %d bytes.\n", mem ); }
Java Code:Number of bytes the JRE will attempt to use = 259522560 bytes.
If you aren't programming in Java, well that's just too bad.
I'd rather be using Ubuntu.
- 08-26-2011, 09:22 AM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Which implies a 1/4 Gb (ish) Xmx by default.
Which seems a bit odd.
Does it have dual processors (or dual core) and only about 1Gb of memory?
- 08-27-2011, 08:51 PM #17
I ran the program on my Core 2 Quad running Ubuntu 10.04 64bit with 6GB RAM
I got the following output:Java Code:import java.util.ArrayList; public class MemoryLimit { public static void main( String[] args ) { MemoryLimit m = new MemoryLimit(); m.memoryLimit(); m.memoryUsage(); } public void memoryLimit() { ArrayList<Character> list = new ArrayList<Character>(); int i = 0; try { while( true ) { list.add( 'a' ); i++; } } catch( OutOfMemoryError e ) { System.out.printf( "Number of one byte characters added to an ArrayList = %d\n", i ); } } public void memoryUsage() { long mem = Runtime.getRuntime().maxMemory(); System.out.printf( "Number of bytes the JRE will attempt to use = %d bytes.\n", mem ); } }
Java Code:Number of one byte characters added to an ArrayList = 130435231 Number of bytes the JRE will attempt to use = 1394409472 bytes.
If you aren't programming in Java, well that's just too bad.
I'd rather be using Ubuntu.
- 08-30-2011, 10:18 AM #18
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks