[{"sl":84,"sc":-1,"el":84,"ec":-1,"m":"Unwritten field: java.lang.ref.SoftReference.clock","p":3,"t":"UWF_UNWRITTEN_FIELD","a":"UwF","c":"CORRECTNESS"},{"sl":84,"sc":-1,"el":84,"ec":-1,"m":"Unread field: java.lang.ref.SoftReference.timestamp","p":2,"t":"URF_UNREAD_FIELD","a":"UrF","c":"PERFORMANCE"}]
How do you optimize the heap size usage of an application that has a lot (millions) of long-lived objects? (big cache, loading lots of records from a db)
Use the right data type
Avoid java.lang.String to represent other data types
Avoid duplicated objects
Use enums if the values are known in advance
Use object pools
String.intern() (good idea?)
Load/keep only the objects you need
I am l...
Java's WeakHashMap is often cited as being useful for caching. It seems odd though that its weak references are defined in terms of the map's keys, not its values. I mean, it's the values I want to cache, and which I want to get garbage collected once no-one else besides the cache is strongly referencing them, no?
In which way does it help to hold weak references to the keys? If you do a Expen...
Anyone can explain why the lines below appear in the output console at runtime ?
(one possible answer would be full permGen, but this can be ruled out since the program only uses 24MB out of the max100MB available in PermGen)
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor28]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor14]
[Unloading clas...
In C++ I'm using boost::shared_ptr and boost::weak_ptr to automatically delete objects that are no longer needed. I know these work with reference counting.
In Java, memory is managed by a garbage collector, which consideres the built-in object references as strong, WeakReference as weak and SoftReference as something in between (may be collected by the GC, but may as well survive the GC), whi...
This question is a result of the answers provided to me for my previous question.
I was asked to use Eclipse MAT to investigate what is eating up my heap. Below are my observations (Top Consumers):
class sun.awt.SunToolkit 333.7 MB
com.tennisearth.service.impl.CacheManagerServiceImpl 136 MB
org.apache.jasper.servlet.JspServlet 91.5 MB
...
Is there a way in Java to do something just before running out of memory. For example, keeping a list of previous document states (for undo) and only removing very old states when memory is about to be exhausted?
I am using an automatic generated Java class for executing a special method. Because of this i have to invoke the method by reflection.
This execution is triggered by a Swing Thread, because the method (invoked from the "unknown" class) is updating a UI Element. Every execution of a new Thread is searching for a Method in the class by calling
Class {
...
public Method[] getMethods() throws Se...
I just came across this answer in SO where it is mentioned that the Google-collections MapMaker is awesome.I went through the documentation but couldn't really figure out where i can use it.Can any one point out some scenario's where it would be appropriate to use a MapMaker.
So I'm using Java to do multi-way external merge sorts of large on-disk files of line-delimited tuples. Batches of tuples are read into a TreeSet, which are then dumped into on-disk sorted batches. Once all of the data have been exhausted, these batches are then merge-sorted to the output.
Currently I'm using magic numbers for figuring out how many tuples we can fit into memory. This is based ...
I guess I'm another person trying to make some kind of a cache with WeakHashMap. And I need some help with it.
I have bunch of TrackData objects that contain information about audio tracks. Then there are Track objects that keep reference to the TrackData inside. Several tracks can point to the same TrackData. Then I have TrackDataCache class that looks like this:
public class TrackDataCache...
I'm writing a Java Swing application that will load from disk about 1500 png images that range in size from 50kb to 75kb each. I don't need to load all of them at once, but I will need to load at 50 images at a time. I've been trying to load them using the typical:
new javax.swing.ImageIcon(getClass().getResource("myimage.jpeg")
but my application freezes and I run out of memory after about ...
I was just digging around in the commons-io library and found this:
Keeps track of files awaiting deletion, and deletes them when
an associated marker object is reclaimed by the garbage collector.
This can be found in the documentation for the FileCleaningTracker object.
Now I am just curious how I can do this by myself? How can my code detect when an object is reclaimed by the garbage col...
In the constructor of my class, I map the current object (this), along with its key (a string entered as a parameter in the constructor) into a static LinkedHashMap so I can reference the object by the string anywhere I might need it later.
Here's the code (if it helps):
public class DataEntry {
/** Internal global list of DataEntry objects. */
private static LinkedHashMap _INTERNAL_L...
Possible Duplicate:
Why doesn't .NET have a SoftReference as well as a WeakReference, like Java?
Java has several types of references, two of these are Weak and Soft. I know that .NET has Weak references but does it have Soft ones too?
(Soft references are stronger than Weak ones in that they will try to keep an object alive even when no strong references exist. They do releas...
I am using ViewFlipper in my android app. After calling startflipping() if I let app to run for some minutes I get soon the error :
11-22 15:36:34.354: ERROR/dalvikvm-heap(428): 307200-byte external allocation too large for this process.
11-22 15:36:34.372: ERROR/(428): VM won't let us allocate 307200 bytes
11-22 15:36:34.375: ERROR/AndroidRuntime(428): Uncaught handler: thread main exiting du...
I have a TableHandler which implements table loading / reloading logic. By table I mean the data I load from either disc or memory when a user request for it in the form of table object. If a new request arrives and the instance of table is in memory then I just loads the table from memory and don't reloads it from disc. If the table I am looking for is not present in memory I just loads the ta...
I am trying to load an image in memory but might have memory issues since i have some other images loaded. These images have a "visible" field that dictates whether they are visible or not. Regardless of the visibility i keep them in memory for fast loading (when they become visible again).
But since i have many of them in memory i want to try to load a new image and if i run into memory issu...
I am working on a simple application that draws small bitmaps onto the screen, and have a little trouble clearing the screen. My bitmaps are stored in an ArrayList called _graphics, and I need to clear the screen, so I clear my ArrayList. This works fine in clearing the screen, however after a while my app force closes.
If I draw around 50 bitmaps on the screen, it will force close the first t...
I have a cache built from a Map to SoftReferences. When they are added they get put into another queue to be lazily compressed down via gzip or some such.
My idea is this: I want to have WeakReferences to the objects in the compress queue, so that when the compressor task gets to the object, if it is already gone we needn't bother compressing it - and also that the compressor's queue doesn't ke...
We have a collection of objects which grows quite large over time. We have implemented a caching strategy to help alleviate this, however we are still running out of Heap Space at run time - if enough memory isn't allocated at startup.
Is there a standard mechanism to reduce the size of this cache at runtime to remove these OutOFMemory errors? This way if our process is started with a smalle...
If I have a List<Object>, would it be possible to run some method on each Object to see how much memory each is consuming? I know nothing about each Object it may be an entire video file loaded onto the heap or just a two-byte string. I ultimately would like to know which objects to drop first before running out of memory.
I think Runtime.totalMemory() shows the memory currently used b...