Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / October 2006

Tip: Looking for answers? Try searching our database.

Run garbage collection

Thread view: 
Wojtek Bok - 30 Oct 2006 18:17 GMT
Is it possible to run garbage collection on a particular instance of a class?

I am manipulating JPG images (rotate, etc). This uses a LOT of memory when processing (about 9Mbytes for a 3MByte image). Once I am done with the
image, all the resources used can be garbage collected.

GC does run when the memory usage gets near 90%, but I would rather it be part of the image processing, that is process the image and right away
recover the memory used.

I know I can request that the JVM run GC overall, but can this be done on a particular object?
Chris Smith - 30 Oct 2006 18:49 GMT
> I know I can request that the JVM run GC overall, but can
> this be done on a particular object?

No.  Because of the way garbage collection works, the virtual machine
would need to basically traverse the entire object graph anyway just to
determine if that object is referenced from any other live objects.  If
that's the case, then you may as well free up all the other dead objects
at the same time.  To do otherwise would be like spending all day
cooking a seven course meal, then eating a biscuit and throwing the
remainder in the trash.

Signature

Chris Smith

Eric Sosman - 30 Oct 2006 18:50 GMT
Wojtek Bok wrote On 10/30/06 12:17,:
> Is it possible to run garbage collection on a particular instance of a class?
>
[quoted text clipped - 5 lines]
>
> I know I can request that the JVM run GC overall, but can this be done on a particular object?

   Probably not.  It would amount to having the program assert
"such-and-such object is garbage," an assertion the JVM would
need to verify before it could be acted upon.  (Consider the
consequences of collecting an object that did in fact have a
few live references still kicking around, whether through error
or through malice.)

   To verify that an object is truly garbage (or that it is not
non-garbage, which may be a better description of contemporary
collectors), the JVM would need to do pretty much the same
amount of work it would do for an ordinary GC.  It seems to me
that "trustworthy selective GC" would not offer much savings
over ordinary GC; TSGC would just complicate the JVM and might
even make ordinary GC slower by imposing extra bookkeeping.

Signature

Eric.Sosman@sun.com

Wojtek Bok - 30 Oct 2006 19:48 GMT
> Wojtek Bok wrote On 10/30/06 12:17,:
>> Is it possible to run garbage collection on a particular instance of a class?
>
>     Probably not.

That is what I thought.

Another problem would be how to do the call, as any usual method needs a reference to the object, yet that is the object we want to GC.

So I guess user one (this is a web app) consumes the memory and user two gets to wait while the GC runs :-))

Thanks!
Chris Smith - 31 Oct 2006 16:52 GMT
>     To verify that an object is truly garbage (or that it is not
> non-garbage, which may be a better description of contemporary
[quoted text clipped - 3 lines]
> over ordinary GC; TSGC would just complicate the JVM and might
> even make ordinary GC slower by imposing extra bookkeeping.

I suppose an exception would be that if the collector were generational,
the call could be interpreted as "collect up to and including the
generation that contains this object".

Signature

Chris Smith



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.