Results 1 to 5 of 5
- 07-31-2011, 11:10 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 4
- Rep Power
- 0
Using the same image several times: does it eat up more RAM?
Hello there :)
I have a question about how images loaded with java.awt.Image are managed internally.
Here's what I'm doing:
I'm writing a Swing component that will be used several times at once because it will appear inside a child window in a MDI setup. And this component loads a PNG image from the disk to draw it as a background.
And I'm not sure how to go with that...
Because if I load that image from the constructor and keep the reference it might load one image in the memory for each window and thus eat up a lot of RAM. Unless Java takes care of making sure that images are loaded only once, but I'm not sure it does so I hoped you could tell me.
The other way I'm considering is to have a ResourceManager singleton class that takes care of loading all the images that my program will need, and store them in a HashMap so they can be picked up anywhere in the code using a string identifier.
What would be the best design?
Thanks :)
- 08-02-2011, 03:18 PM #2
Member
- Join Date
- Apr 2011
- Posts
- 4
- Rep Power
- 0
Any idea? :s
- 08-02-2011, 04:17 PM #3
Have you done any profiling at all? Your first question is best answered by writing a program and testing it yourself- feel free to post it in SSCCE form. Let us know when you do that, and we'll go from there.
How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 08-02-2011, 04:21 PM #4
What do you mean by
images loaded with java.awt.Image
Unless Java takes care of making sure that images are loaded only once
db
- 08-02-2011, 04:50 PM #5
Member
- Join Date
- Apr 2011
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Looping WAY too many times...
By BariMutation in forum New To JavaReplies: 10Last Post: 10-15-2010, 11:27 AM -
Times without dates.
By JavaJuJitZu in forum Advanced JavaReplies: 14Last Post: 01-17-2010, 11:54 PM -
My buttons all perform their action like 100 times
By 711groove in forum New To JavaReplies: 0Last Post: 12-13-2009, 11:49 AM -
Difference in seconds between two times
By jazzy639 in forum New To JavaReplies: 11Last Post: 09-26-2009, 07:58 PM -
SwingWorker problem!!! How can I run it 2 times or more?
By davigre in forum AWT / SwingReplies: 3Last Post: 10-02-2008, 06:48 AM
Bookmarks