• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Find the size occupied by String in Android

Valak19

Lurker
I have an EditText in Android in which I enter text and store all those text in a Custom ListView. I want to calculate the memory occupied by the String in that EditText and thereby maintain a list of space occupied by each text.

Ex: S = "My favorite movie is Inception".

The length of S is 30. How much space will it occupy in the phone and how do I calculate it?
 
Well yes there is a certain overhead to storing all objects on the heap, in terms of object references. But using Strings is so common in a Java program, that the JVM optimises their storage by putting them in a String pool, a special area of memory allocated for String objects.
So if you create a new String object in your code, it may have new memory allocated to it, or it may simply refer to a String object already available in the pool. This is not under your control.
 
Back
Top Bottom