answersLogoWhite

0


Best Answer

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

8y ago
This answer is:
User Avatar

Add your answer:

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

This key word causes an object to be created in memory?

To instantiate a object, we use the new keyword in Java, which creates an object in memory.


What is the memory overhead of an object in Java?

see http://www.javamex.com/tutorials/memory/object_memory_usage.shtml


When does the memory created for an object?

Memory for a Java object gets created when the object is instantiated. For example private String name = "rocky"; At the end of this statement the memory for the string object name gets created in the memory.


How do you find size of any object in java OR is there any operator or fun.. equivalent size of in c plus plus?

No, there is no such operator or function in Java that can tell you the amount of memory an object uses.


What is an object in Java?

object is an instance of a class. it's used to allocate memory dynamically at run time to access class members.


What are objects in java?

Object is like a variable of the class type which references the memory required by the attributes of the class.


What is GC in java?

GC stands for garbage collector - this is the mechanism which cleans up unused object references. The GC is why memory management in Java is almost non-existent.


How do you find the size of a class object?

Java does not have a sizeOf() operator and hence there is no way we can actually determine the size of a java class object. However we can analyze the overall heap space utilization to try to get an approximate indication of how much memory is used by an object but it is not accurate.


What is memory leak problemin java?

Memory leaks do not occur in Java as the garbage collector clears the memory which has no references.


What is a java object?

A java object is a collection of methods and properties defined in the Java programming language.


How do you delete an array object in java language?

The Java Virtual Machine takes care of all the actual deletion for you. Once an object no longer has any references left, the garbage collector will come along and clear up that memory automatically.


Can a Java application have memory leak?

Java has a fairly sophisticated garbage collection system, and in general you don't worry about memory leaks, as they only happen in a few very specific circumstances (notably, when adding listeners to Swing GUI objects and not removing them). If you need more sophistcated memory management, java provides the clases in the java.lang.ref package.