forum

Home / DeveloperSection / Forums / Do null properties of Java objects use memory?

Do null properties of Java objects use memory?

Anonymous User 1613 20-Jul-2015
I am connecting to a webservice that sends down many different JSON objects. Rather than use a Java JSONObject I plan to use the GSON library to convert to POJOs. Rather than a huge amount of classes (one for each of the possible JSON service responses), I want to have a generic java object that can hold all possibilities:

public class GenericJSONResponse{
    public long objectKey;
    public GenericJSONResponse subObject1;
    public String description;
    // ...
}
I think this is a good aproach since the properties that get sent down by the server vary greatly. All server responses will only include a subset of the possible GenericJSONResponse properties. Will the properties that do not get populated take up memory even if they are null? My generic object will have many properties that are not used and I don't want them taking up precious memory.

Updated on 20-Jul-2015
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By