0

Is having Java static final String (constants) will save heap space?

Analyzing java heap dump of 1G showing up duplicate strings cost around 300M+ which means a lot for a app using max of 1G heap...

why there are duplicate Strings?-- few Tables have createdUser and modifiedUser columns, mostly these values refer to 20 usersnames all DBobjects holds this values as strings which in return causes duplicate values.... thinking to create 20 names as constants and refer them this constants at time of object creation? not sure how this idea works or best practices, looking for better solution and knowledge to deal

JAVAC
  • 1,230
  • 3
  • 17
  • 38
  • 1
    You have shown us no code nor any profiler results, so how are we supposed to know? All we can with the info you've given us is make assumpsions – Vince Jul 20 '16 at 21:35
  • 1
    Java 9 is likely to have a features where it a) uses byte[] for Strings and b) de-duplicates the byte[] for Strings. – Peter Lawrey Jul 20 '16 at 21:49

0 Answers0