It depends on what type of container you are using, a simple Java array, a
List
, or any other custom developed container. Each of these containers either have a zero, constant, or somewhat variable overhead to maintain other operations. Like a
List
type might store some extra memory space to provide a faster insertion, whereas arrays take up O(N) space...
Quote:
i want to create large number of objects in java so the the memory overhead is minimum
I am not sure I follow you on this or not, but each object is going to take its own space in the memory, either created via loop, function calls, or internally.
Objects in Java are references to their instances, creating an array of 1000 objects does not mean you create 1000 objects, you would have to
new
them at some time later. That is how Java's type system works.
Quote:
memory overhead associated with the concept of creating objects in java
How Java handles that underlying inside the JVM, that much I am not sure but it does have a function call that creates the object itself, and any internal objects or structures. It is mostly a recursive call, any
overhead associated with them is basically because of internal creation of objects, and getting the references of the variables and their objects—JVM realm.
Last but not least, do not bother with the internals of Java unless you have to write a compiler, otherwise, just do your best at a high-level. See here,
Creating Objects (The Java™ Tutorials > Learning the Java Language > Classes and Objects)[
^]