answersLogoWhite

0

An object in Java may contain a small amount or a large amount of memory - it depends almost entirely on what you store in it. For example, a String is an object. Now, you can have a String that contains 10 characters - that object will contain 20 bytes (2 bytes per character - characters are stored as Unicode), plus a small amount of overhead. The amount of overhead may vary, depending on the specific Java implementation. Another String, which contains 100 million characters, will be stored using 200 million bytes (plus a small amount of overhead).

I believe the JVM may also round the space used up by an object up - for example, to the closest power of two. But once again, this is implementation-specific.

User Avatar

Wiki User

9y ago

Still curious? Ask our experts.

Chat with our AI personalities

DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
ReneRene
Change my mind. I dare you.
Chat with Rene

Add your answer:

Earn +20 pts
Q: Memory occupied by object in Java?
Write your answer...
Submit
Still have questions?
magnify glass
imp