• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OutOfMemoryError - how do I find out where the memory is going?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My program keeps giving an OutOfMemoryError. I was wondering if there were any tips to find out where the memory is going. I can't seem find a pattern to when it gives up the ghost. I have put a Static count variable into each of my classes which increments in the constructor and takes off one in the finalize method and prints out the count. This seems to be behaving as I expected ie. there is the correct number of each of my objects.

Thanks
 
Author
Posts: 531
Mac OS X Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use profilers to find memory leak in your application (if you cannot figure it out by logging or tracing the code execution)

there are plenty of profilers available to java developers. one of them is Netbeans profiler (if you use netbeans you can use this profiler) im sure that thre are profilers for eclipse like jProiler and yourkit java profiler.

but for free you can use netbeans profiler from www.netbeans.org
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Increase the heap size, dude. Just don't increase it too much.

Heap size. That's my trick. I know WebSphere Portal goes out of memory as soon as you turn it on if you don't boost the heap size up after installation.

-Cameron
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A couple easy ways to accidentally chew up all memory are recursive routines that forget to bottom out and return, and loops that forget to stop and keep creating objects. If your out of memory problems occur suddenly at startup or right after kicking off some operation, you might look for those situations.

With JDK 5 and later you get JConsole which will let you watch memory use and object instance counts. Those might give you a clue how fast the problem comes on and when it starts.

Of course it may be you don't have a coding bug at all, but just use a lot of memory. If that's the case you may be able to bump up the heap to handle it. Let us know what you find!
 
Cate van Alphen
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone. I have tried some profilers and now I'm REALLY confused! I've tried JConsole and NetBeans. I'm a bit overwhelmed with the info from NetBeans, but it seems there are a lot of int[] from BufferedImage. My program is a sort of flower hybidising thing. I have a singleton class called FlowerSimState which holds all the information, and the panels of the gui are registered as observers. What's really confusing me is that if I press the button with the OffspringListener repeatedly (50 times), the memory usage constantly increases untill it dies. If I press the RandomListener button the memory fluctuates, but it calls the same function as the OffspringListener! If I press other buttons, the OffspringListener still kills the program but at a less predicatable rate.

I've included some code, but it's not all there as I tried to simplify to make it more readable. I only realise how confusing my code is when I try to explain it to someone else.











 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have used JCONSOLE to save with this error OutOfMemoryException. It will good runtime analysis of your application.
reply
    Bookmark Topic Watch Topic
  • New Topic