aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes memory allocation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "memory allocation" Watch "memory allocation" New topic
Author

memory allocation

gylph knor
Greenhorn

Joined: Jun 12, 2008
Posts: 20
hi all,

could anyone please explain that if i make 1000s of instances of the same class then how will the memory be allocated to the instances of the class( i mean to diffent parts of the class i.e methods and attributes ) ...... please help !!!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Are you trying to say that will JVM be out of memory. If yes, then the JVM might go out of memory to allocate for the objects and throw an OutOfMemoryError...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
gylph knor
Greenhorn

Joined: Jun 12, 2008
Posts: 20
no i mean to say that if my class takes 1 mb of memory in total then for suppose 10 objects will there be an allocation of 10*1mb=10mb of memory??
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

i mean to diffent parts of the class i.e methods and attributes


The size of an object of a class depends on the instance fields. Methods don't occupy memory in a class object (as far as I know). static fields also are shared among instances of a class. so they also don't occupy memory in individual objects of a class.

if my class takes 1 mb of memory in total


if an object of your class occupies 1mb, then 10 objects will occupy 10 mb memory.
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
Yes, that's true. 10mb, according to your example, would be the memory used for the objects of your class because each object would be using its own space over the heap. But then taht 1mb should be the memory taken by the object, apart of the loaded class.


Experience and talent are independent of age
gylph knor
Greenhorn

Joined: Jun 12, 2008
Posts: 20
thnaks !! got it ..
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

gylph knor wrote:no i mean to say that if my class takes 1 mb of memory in total then for suppose 10 objects will there be an allocation of 10*1mb=10mb of memory??

Hmmm... quite a spacious class
But on the other hand you can create one big array and it will be allocated.


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: memory allocation