• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Memory leak problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
laxminarayana garlapati
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thank you for your reply.
I will try with -Xmc command.
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic