wood burning stoves 2.0*
The moose likes Java in General and the fly likes Memory Leak Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Memory Leak" Watch "Memory Leak" New topic
Author

Memory Leak

Manoj Amrutkar
Ranch Hand

Joined: Apr 15, 2006
Posts: 47
I am getting this error in my swing application

"java.lang.OutOfMemoryError"
My Application has different form, which are opened one after another in page down key stroke, If i goes to fast(page down key press) above errors comes.

Frame is contaning internal frames. which displays my forms (one at a time)
Internal frames contains layered pane on which bottom layer i have used .gif images (which are the once creating the problem as there size is bit large say around 300 KB) to show forms.

Code is something like this on every page down




My problem is these images loaded in memory are the once creating the problem.

Please suggest something which will help in this regard

Some thing which will clear up (garbage collection), before next page down.

Thanks

Manoj
Joseph Kampf
Greenhorn

Joined: Mar 04, 2004
Posts: 26
Well the problem is your holding onto these images. You get too many of them and you are storing copies of them. Even if it is the same image.

Can your heap size handle 1 copy of each of the 4 images? Instead of loading them each time, you could cache references to each of the 4 and just point your myImage value at the correct reference.

Another option is to synchronize your method. This will at least ensure that you only have 1 valid reference to myImage at a time.


Originally posted by Manoj Amrutkar:
I am getting this error in my swing application

"java.lang.OutOfMemoryError"
My Application has different form, which are opened one after another in page down key stroke, If i goes to fast(page down key press) above errors comes.

Frame is contaning internal frames. which displays my forms (one at a time)
Internal frames contains layered pane on which bottom layer i have used .gif images (which are the once creating the problem as there size is bit large say around 300 KB) to show forms.

Code is something like this on every page down




My problem is these images loaded in memory are the once creating the problem.

Please suggest something which will help in this regard

Some thing which will clear up (garbage collection), before next page down.

Thanks

Manoj
Ernesto Elias-Nieland
Ranch Hand

Joined: Sep 01, 2005
Posts: 53

This code is missing where you store your images. After the method you show completed all images will be gc'ed. So there should be no out of memory error. Somehow you keep a reference of all images.
As a solution I would suggest (if there are just some different pictures): 1. create all of them on application startup and save them in a HashMap.
2. Give every new frame a reference to the HashMap.
3. Pull the image out of the HashMap in your method and show the picture.

By this you have just one image object for every picture.

Cheers,
Ernie


0x2B | ~0x2B
SCJD, SCJP 1.5, SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJA, IBM Test 150, 142, 700, 701, Oracle Test 1Z0-51
 
Consider Paul's rocket mass heater.
 
subject: Memory Leak