开发者

Java App with lots of memory problems

I've written a pretty complex java application that is doing a lot of calculations on price data from the markets in real time and from looking at the task manager in windows this sucker is taking close to 1MEG every 30 seconds and the performance is fine until it gets closer to the memory limit around 300MEG and then the g-collector really kicks in and spikes my CPU to around 50% and the UI performance rapidly degrades from all I've written 开发者_开发知识库so far it sounds like I have some bad code going on because the nature of my program is CPU intensive but by design stores very little data in memory.

I need some help on what might be some good next steps to take to see how I can figure out what the problem is, I think if I can see what objects are getting stored in memory that would help as maybe I have some lousy code but I am heart broken with Java as I thought these are problems I would not have to worry about. Thanks for any answers. - Duncan


  1. Identify some reasonable performance targets (memory usage, throughput, latency).
  2. Put together some repeatable performance tests, the closer you can get these to real life scenarios the better.
  3. Get a hold of a good profiler. I've used YourKit with a lot of success, the Netbeans and Eclipse profilers are not bad either. Most decent profilers will be able to identify memory usage, GC and performance hotspots.
  4. Identify the biggest culprits and start fixing the issues beginning at the TOP of the list.


Check out VisualVM. It's in the current JDK bin directory as jvisualvm. If you don't have a memory leak, the heap usage should go down when you run the garbage collector, and you can see which objects may be holding memory by calculating the retained sizes of objects in the heap.

http://download.oracle.com/javase/6/docs/technotes/guides/visualvm/intro.html


Like others say, use a profiler to find what is consuming the memory.

If you don't know already, the garbage collector can only release memory on objects that are out of scope. That is, don't have any references to them. Just make sure it goes out of scope when your done with it. It sounds like your locking it up in a way were it's still referenced some where.

Also, if you want to suggest to the GC that it cleans up, try this:

System.gc();
System.runFinalization();

Again, that is only a suggestion to the gc; but I've found it really helps if you run it after a lot of objects go out of scope.

Lastly, you can tweak your vm arguments. There are settings for min/max heap size settings. If it's a critical application set them to the same and set it high (that way it doesn't have to keep allocating/deallocating - it just grabs one big chunk at startup). This isn't a fix, just a workaround.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜