Katrin said:
Hi again,
assume I have a java programm that will create about 500000 (half a
million !) objects (which are of a very easy type, just about 10
instance string-variables).
Do u think there will be a memory problem (on a "normal" pc with 256-512
MB RAM) or any other constraints or problems due to that big amount of
objects ?
thanx for your answers.
Katrin
You'll very likely have problems:
Let's do the calculations, assuming you're on a 32 bit platform.
Each object has an overhead of about 12 bytes:
<
http://www-106.ibm.com/developerworks/ibm/library/i-garbage1/>
You have 500.000 custom Objects, that each have references to 10 String
objects, which hold a char array object. We'll also need to count the
reference to each object (32 bit)
So you need about (500.000 + (500.000 * 10) + (500.000 * 10)) * (12B + 4B) =
+-160MB for the Objects and their refs.
But you also need to keep the instance fields of the Strings themselves in
count:
3 ints and a char array (we've already counted the ref + the overhead of the
char array, now we need to count the contents of that char array. Let's
assume an average String length of 10 chars (a 16 bit primitive):
(10 * 4B) + 12B = 52B / String
5.000.000 * 52B = 247MB for the actual String data.
So you'll need a minimum of 160 + 247 = 407MB to hold all those objects in
memory at once.
This could be much less if many of the Strings were the same. The best case
scenario, in which you always reference the same, empty String, only takes
about 500.000 * (12B + 4B) + 500.000 * 40B = +- 26.7MB