Require some insight regarding Objects
Roman Kennke
roman at kennke.org
Mon Nov 13 15:57:20 UTC 2017
Am 13.11.2017 um 16:27 schrieb Prakhar Makhija:
> *json*
>
> {"subCategory":"European","bornLocation":"Pondicherry","name":"Goldi
> Heathers","someSocialStatus":"Active","prefferedCategory":"Within
> City","dateOfBeingBorn":"16/11/1987","interestedActivity":"Business","personalEarnings":500000.0,"matchfulDesiredEarnings":1000000.0,"identificationNumber":"X582TQ0170TF47002UTD087X74","prefferedClass":"Private","addressState":"Andaman
> and Nicobar Islands","someAddress":"House Number 143, Near Pie Beach, Port
> Blair, Andaman and Nicobar Islands, India -
> 744101","interestedActivityCode":72681.0,"emailId":"munchymuffin at gmail.com"}
>
>
> *class definition*
>
> public class MyClass {
> private String identificationNumber;
>
> private String name;
> private String someAddress;
> private String addressState;
> private String bornLocation;
>
> private String someSocialStatus;
> private String prefferedClass;
> private String prefferedCategory;
> private String subCategory;
>
> private String dateOfBeingBorn;
>
> private String interestedActivity;
> private Double interestedActivityCode;
>
> private Double personalEarnings;
> private Double matchfulDesiredEarnings;
>
> private String emailId;
> // getters & setters
> // constructors
> }
>
>
> *code block*
>
> import com.fasterxml.jackson.databind.ObjectMapper;
>
> ObjectMapper objectMapper = new ObjectMapper();
> MyClass myClassObj = objectMapper.readValue(currentLine.getBytes(),
> MyClass.class);
>
>
> *topic*
>
> Likewise having 1.5 million json files
> Total size which they are occupying on disk is 940 Mega Bytes
>
> My first doubt is when I load all these json, to make objects out of them,
> will they occupy the same space in the memory?
Unlikely. Because json is just character strings, while java objects are
packed data. But see below:
> My second doubt is about what is going on internally in the JVM's memory,
> when I am making 1.5 million objects of MyClass.
> Lets pick one identifier 'identificationNumber', it has 20 characters.
> So just this field 'identificationNumber' is going to occupy 40 bytes only,
> or (40 * 1,500,000) = 60,000,000 bytes = 57.22 MB
> ????
Identifiers aren't accounted for every object. The compilers translate
them to an index in object memory.
You'd get a better picture if you actually load all those objects and
serialize them to disk. Only the actual values are allocated for each
object, and even then you can have strings deduplicated and/or interned.
Hope that helps?
Roman
More information about the discuss
mailing list