• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to calculate the size of a graphical object in memory?  RSS feed

 
Ricardo Marques
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I am writing an application and I need to display a lot (10000+) of graphical components (JLabel's with icons). I may have to display them all at the same time in JScrollPanes.

Is there a way for me to calculate how much memory will this take?

I know that each object itself in memory occupies X bytes, but I would like to know how much more does the graphical representation take. Lets assume my icons are 100x100 pixels at 16 million colors each (worst case scenario).

How could I achieve an approximate value of the memory occupied by the graphical representation?

Thanks a million.
 
Ted Reynolds
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that there is no compression in the imager (worst case) and that you are including the alpha channel in the calculations, each pixel would take 4 bytes (8 bits each for red, green, blue and alpha). this would bring the grand total for your size of icon to 40,000. I would then add 10% to this just to be on the safe side.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!