Originally posted by Jack Shirazi:
Ouch, three threads, two forums. Well I'm only replying here.
Q3 When the gc decided to clear the soft references it sweapt all of them, not just the ones necessary to get enough free memory.
A3 Yes, this is how it works, all or nothing.
If you don't want them garbage collected, don't use weak references. You might be better off with an object database that would swap the objects to and from disk.
Lets take another tack. Either
1. you can get the JVM big enough to handle all you want using -Xms, in which case don't use weak references at all; or
2. you cannot get the JVM big enough, so you need some mechanism for regaining the objects and minimizing garbage collection. In this case, you need to determine what the high water mark is (Runtime.totalmemory). Then create a runtime policy which keeps account of objects created, and deliberately dereference objects for garbage collection when you are near the high-water mark and
want to create more. Use a centralized object creation mechanism, it helps keep account. (also try recycling more objects).
Most applications that need this kind of manipulation of large amounts of data end up needing to use a disk based store of some kind - file storage, RDB or ODB. You can roll your own with serialization, but it won't be particularly efficient.
--Jack Shirazi http://www.JavaPerformanceTuning.com/
Originally posted by Peter Tran:
Andreas - read this topic relating to finding the size of JAVA object: http://www.javaranch.com/ubb/Forum15/HTML/000098.html
Jack - thanks for the reply.
-Peter
Originally posted by Jack Shirazi:
Okay, SoftReference GC is not actually all or nothing: there is no actual guarantee of anything other than that at some point you may find any one SoftReference cleared. The actual implementation is JVM dependent. But in practice I think it is easier to implement it all or nothing.
I don't really think this makes them useless for caching. I don't think they are intended for such large amounts of data to be cached as you want.
As for your customers' decisions, bear in mind that heap size was set previously - only you were using the default values (2 megs initial and 64 megs max). So you're only making them make a conscious choice instead of the default, and you are just setting your own more appropriate default to be nice.
--Jack Shirazi http://www.JavaPerformanceTuning.com/
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|