Creating & Destroying Objects

THIS Section concerns creating and destroying objects:

  • When and how to create them,
  • When and how to avoid creating them,
  • How to ensure they are destroyed in a timely manner, and
  • How to manage any cleanup actions that must precede their destruction.
Objects Management memory-map
Following Rules are described
  1. Consider static factory methods instead of constructors
  2. Consider a builder when faced with many constructor parameters
  3. Enforce the singleton property with a private constructor an enum type
  4. Enforce non-instantiability with a private constructor
  5. Prefer dependency injection to hard-wiring resources
  6. Avoid creating unnecessary objects
  7. Eliminate obsolete object references
  8. Avoid finalizers and cleaners
  9. Prefer try-with-resources to try-finally