This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes GC behavior on Serializable objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "GC behavior on Serializable objects" Watch "GC behavior on Serializable objects" New topic
Author

GC behavior on Serializable objects

Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Hi Ranchers,

I am trying to fix the performance problems in my application.

1. How does a serializable object serialized. When I profiled the application, I never see this object GCd.


I use sweetdev ria tree in my application.

On every refresh of my JSP page, increases new objects which are related to the tree. My TreeDataProvider implements ITreeDataProvider which extends Serializable.

The objects are removed from memory only when I restart my tomcat. I have controlled the increase of memory due to nodeTypes, by making the node types as constants. But I could not make the TreeDataProvider a constant as it varies and not a constant.

I am not sure on what do I miss here. Does gc behaves differently if my class extends Serializable?

Any helps would be appreciated.

Regards
Ananth Chellathurai


Ananth Chellathurai [Walk on software]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
Does gc behaves differently if my class extends Serializable?


No. If the object is not GCed, there is probably a reference to it hanging around somewhere.

Bill
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
Why do you implement Serializable?

Do you serialize it to disk or do you remote the object?
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

No, I am using sweetdev ria library, the dataprovider class implements ITreeDataProvider which extends Serializable.
I do not want my objects to be stored to the disk. Not sure on whether the license terms allows me to edit the code.

Ananth Chellathurai
[ September 26, 2008: Message edited by: Ananth Chellathurai ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
What provision does the "ITreeDataProvider" class have for cleaning up after you are finished with an instance?

Bill
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Do you get OutOfMemoryErrors? If not, it might just be that the gc decided that it isn't yet time to gc the instances.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

I do not get outofmemory errors, however when I refresh the jsp page, I see the memory keeps growing for every refresh.

Ananth Chellathurai
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Ananth Chellathurai:
I do not get outofmemory errors, however when I refresh the jsp page, I see the memory keeps growing for every refresh.


That's normal behavior. Just because an object *could* be gc'ed, it doesn't mean that it necessarily *will*.
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

How do I force an object to be gced, other than using System.gc, I would like a specify an object to get gced.

Is there any other suggestions to fix my memory problems?

Ananth Chellathurai
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
Lets get back to the original question:
I am trying to fix the performance problems in my application.


Exactly what is the performance problem?

If you are not running out of memory, why are you worrying at all? Let Java take care of the memory GC and get on with programming the application.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GC behavior on Serializable objects
 
Similar Threads
Garbage Collection and Virtual Memory
Serialization Problem
HI please Help with. GC Kathy and Bert Book
Doubt in GC
Heap used for a simple program seems too much