1

Currently I am experimenting with CDI @ConversationScoped beans following the Oracle Tutorial.

While monitoring memory usage, I found for a bean with two collections of 800+ Objects and other few objects its taking more than 60MB session space.

I am aware, it has to maintain the whole view state and changes in conversational context, but taking this huge amount of memory really surprises me.

Is there anything I might be missing or any way to make the bean more memory efficient.

shakhawat
  • 2,639
  • 1
  • 20
  • 36
  • *"a bean with two collections of 800+ Objects"* is in first place wrong. CDI can't do much against such an implementation. You'd better take a step back and look at e.g. pagination/filtering, JPA L2 cache, etc. – BalusC Apr 16 '16 at 14:40
  • Wow, comment from BalusC, really a lucky day for me. I am looking into pagination/filtering. Had a little prior working knowledge of JPA L2 cache – shakhawat Apr 16 '16 at 18:00
  • 1
    Bean should hold only the data which is absolutely necessary to present to the enduser. E.g. if you're presenting it in a (paginated) HTML table, then simply load and hold only the records for the current page in bean. Usually it are only 10, 25 or 50. – BalusC Apr 16 '16 at 18:02
  • Currently after fetching the list i am presenting it using primefaces datatable. Holding only records of requested page is a good idea, looking into implementation details. – shakhawat Apr 16 '16 at 18:09
  • 1
    PrimeFaces? That's even more easy. It supports `LazyDataModel` out the box: http://www.primefaces.org/showcase/ui/data/datatable/lazy.xhtml Inside the overriden `load()` method, just load *exactly* the records based on offset/limit/sorting/filtering provided via `load()` arguments. Noted should be that their example is kind of confusing because a "static" `List` is used for demonstration purposes (i.e. not DB based) which they then `sublist()`, but you should ignore that part. – BalusC Apr 16 '16 at 18:12
  • ```LazyDataModel```, really interesting. That solves the large collection problem nicely. Thanks a lot :) Started working on it – shakhawat Apr 16 '16 at 18:21
  • 1
    Which of those is most helpful? http://stackoverflow.com/q/13972193 or http://stackoverflow.com/q/5548587? – BalusC Apr 16 '16 at 18:38
  • Went through both, got the main idea, should do range query instead of subList approach. Many thanks :) – shakhawat Apr 16 '16 at 19:19

0 Answers0