Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java.lang.OutOfMemoryError 1

Status
Not open for further replies.

russland

Programmer
Jan 9, 2003
315
CH
my tiny application is supposed to resize images. a selected image. For some reason it required more than 256MB to resize the image applying the function below on a 8MB JPG file. Of course, I could broaden the memory scope for the application, but that seems to be the wrong approach - since macromedia fireworks requires less than 20MB RAM to resize the image in record time. Any guess how to minimize the memory eating? Any way to apply dynamic memory allocating.

thanks

public RenderedOp resize(PlanarImage planImg, float resizeFactor){
ParameterBlock pb = new ParameterBlock();
pb = new ParameterBlock();
pb.addSource(planImg);
pb.add(resizeFactor);
pb.add(resizeFactor);
pb.add(0.0f);
pb.add(0.0f);
pb.add(new InterpolationNearest());
RenderedOp img = JAI.create("scale", pb, null);

return img;
}
 
Java is a terrible memory hog. If the code snippet you posted is really all you're doing, then just increase the memory for the application and move on to more important things.

If you're really interested, download a copy of Oracles JDeveloper and run your app under it. It has a built in memory profiler that will tell you what's using up all the memory.
 
answering another question I posted. You may force the garbage collection to run. Helps nicely for memory intensive applications.


Runtime rt = Runtime.getRuntime();
rt.gc();
long mem = rt.freeMemory();
System.out.println("Freed Memory: " + mem);
 
Bear in mind that the call to System.gc() is only a hint to the JVM that GC is requested - and not actually a guaranteed call (according to the JVM implementation spec).

So you should never actually rely on the fact that when you call System.gc() that it will actually happen.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
okay, I'll bear in mind. thanks, I appreciate these kind of comments.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top