my dog learned polymorphism*
The moose likes Java in General and the fly likes Memory leak problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Memory leak problem" Watch "Memory leak problem" New topic
Author

Memory leak problem

laxminarayana garlapati
Greenhorn

Joined: Apr 17, 2007
Posts: 2
Hi,
I am facing memory leak problem in Java.

I have written one java program to load some image files and display it in different sizes.

For this I have used BufferedImage, Graphics2D, MediaTracker, Image , JPEGImageEncoder, JPEGImageEncoderParam, RenderOp,ParameterBlock classes.
When I run this, I am getting �OutOfMemory�, "core dump" exceptions.

To avoid memory leak I have closed BufferedImage, Graphics2D objects by calling flush(), dispose() methods.

But still I am getting the same exception.
Anyhing else i need to close and any other solution for this?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Are you sure that it is a memory leak or does your program really need more than the default amount of memory (64 MB with Sun's JRE on Windows)?

You can use the -Xmx switch (see the documentation) to let the JRE allocate more memory than the default amount.

If you think it is really a memory leak, use a profiler, or maybe JConsole to find out where the memory leak is.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
One possibility is the MediaTracker. If you're using a single MediaTracker for many different images, then be sure to call removeImage() when you're done with a given image. But if you're using a different MediaTracker each time, and letting each MediaTracker get GC'ed when you're done with it, then this should not be an issue.


"I'm not back." - Bill Harding, Twister
laxminarayana garlapati
Greenhorn

Joined: Apr 17, 2007
Posts: 2
Hi,
Thank you for your reply.
I will try with -Xmc command.
 
 
subject: Memory leak problem
 
Similar Threads
new image after rotate
creating an image from an modified component
creating an image from an modified component
Image Handling in Java
Calling a Java class from a servlet to display images dynamically.