Forums Register Login

Image and memory problem

+Pie Number of slices to send: Send
Hi!
I have a function to load 3 images and I give the reference of this image object to an JPanel where i display it. I must call the function very offen. After 5 times i have a memory usage of 80 MB RAM!!! That's not good. Can you help me please, i need a similar better function or my program is not working. I wrote an apllication...
My function:

Thanks a lot!
[ September 19, 2002: Message edited by: Kay Tracid ]
[ September 23, 2002: Message edited by: Kay Tracid ]
+Pie Number of slices to send: Send
I have not worked with mediatracker, yet. But what I can see from your code is, that you only add images to the mediatracker, but never remove them. Maybe the mediatracker does not reset the values but holds the references to all images ever added. If this is the case, than no wonder your program's memory explodes.
cheers
c
+Pie Number of slices to send: Send
I'm not sure if MediaTracker is the problem, but if it is, it could easily be solved by making it a local variable in your loadPics() method. That way the reference wouldn't hang around as a class level attribute.

In addition... What is PicPanel doing? And what is the variable tr? Also how big are the images? Do you know that this is the code that is causing the memory problems?
+Pie Number of slices to send: Send
You create Image object to use, but you should destroy it's resource, you should try java.awt.Image flush method, before you load it next time.
+Pie Number of slices to send: Send
Ok, thanks for your answers. "tr" is not important I removed it in my source code. PicPanel is a simple Panel with 3 functions, where you can set 3 images. With a button in the panel you can change between them. I think MediaTracker overwrites the images before(because it is always the same ID), but I will try it with a local variable. I will also try the flush method.
Thanks a lot!!
Have you no shame? Have you no decency? Have you no tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 777 times.
Similar Threads
How to get an image from an http address into Image object directly
getImage()
Casting problem. Image to BufferedImage
still memory problem with image loading
how can i refresh a scrollpane
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:38:08.