• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

memory allocation

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!!
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
gylph knor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
gylph knor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnaks !! got it ..
 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic