It's not a secret anymore!
The moose likes Java in General and the fly likes Size of a session object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Size of a session object" Watch "Size of a session object" New topic

Size of a session object

Marilyn Monickam
Ranch Hand

Joined: Jun 05, 2001
Posts: 66
Could you let me know if there is a way to determine the size of a session object or any object?
Greg Charles

Joined: Oct 01, 2001
Posts: 2968

There's no sizeof operator like in C, if that's what you mean. Java tries to abstract you from the idea of the physical memory. However, if you use a profiler like OptimizeIt, you can get some idea of how many objects of each type have been allocated, and how much memory they take.
On the other hand, if you meant how to get a count of the attributes currently contained in a session (and you're talking about an HttpSession), I don't see an obvious way. You have to getAttributeNames(), then cycle through the Enumeration to count them.
I agree. Here's the link:
subject: Size of a session object
jQuery in Action, 3rd edition