• Post Reply Bookmark Topic Watch Topic
  • New Topic

Image and memory problem

 
Kay Tracid
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Zhao Fu Qiang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kay Tracid
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!