javacachingmemoryheap-memoryobjectpool

How do you make your Java application memory efficient?


How do you optimize the heap size usage of an application that has a lot (millions) of long-lived objects? (big cache, loading lots of records from a db)

I am looking for general programming or Java specific answers. No funky compiler switch.

Edit:

Optimize the memory representation of a POJO that can appear millions of times in the heap.

Use cases

Resume of answers:


Solution

  • You don't say what sort of objects you're looking to store, so it's a little difficult to offer detailed advice. However some (not exclusive) approaches, in no particular order, are:

    Knowing more about the internals and lifetime of the objects you're storing would result in a more detailed answer.