How to Reuse Objects Instead of Creating New Ones If Possible in java?

Reuse Objects Instead of Creating New Ones If Possible

Object creation is an expensive operation in Java, with impact on both performance and memory consumption. The cost varies depending on the amount of initialization that needs to be performed when the object is to be created. Here are ways to minimize excess object creation and garbage collection overhead:
  • Use a Pool to Share Resource Objects
  • Recycle Objects
  • Use Lazy Initialization to Defer Creating the Object Until You Need It.

Comments