This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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.
 
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.
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!