Skip to main content

Image Memory, Image Buffer - flush and dispose

5 replies [Last post]
elbob
Offline
Joined: 2008-10-01
Points: 0

Hello Everyone,

i've been trying for a while but I can't find a way to dispose my image buffer to be able to use more than these 12 MPixel per project.

My starting point is HD Cookbook and the additional info on the cookbook site: http://wiki.java.net/bin/view/Mobileandembedded/BDJImageMemoryManagement

I'd be happy about any hints or test results.
----

Facts (?)
- When I call .flush() on an Image (I also set it to null and called System.gc() ) the Memory for this Image should be freed. Right?
- When I create a Full Screen DVBBufferedImage it takes up the same space as an ordinary Full Screen Image - no matter how much I paint into its Graphics Object. I can free it using the dispose() Method - but as long as I want to paint I don't have to. Right?
----

I did some testing, but the results don't make me see clearer. Can anyone explain what's going on here? I'm loading one image after another with a few Seconds sleep() between and a repaint to see if it was loaded successfully.
----

1. No double Buffering, no flush:
Everything as it should be. All Players load as many Images as they should depending on Profile.

2. Double Buffering, no flush:
Everything as it should be. All players load 1 Image less that before, because of Full Screen BufferedImage

3. No Double Buffering, flush called before loading next Image:
PS3 loads ALL my images as it should - all other players react like there was no flush.

4. Double Buffering, flush called before loading next Image:
All Players act like there was no flush (Also PS3)
----

Isn't that strange? Especially the PS3! Am I missing anything?
I even tried to dispose and create an new DVBBufferedImage at every repaint.
----

Thanks a lot! This is making me crazy...
elBoB

----

Additional questions just for fun :)
--
The property telling me the image memory size didn't work on my players - has anyone seen it work on any player? (winDVD works)
Can I read the actual memory usage?
When I create an Image - is there a way to find out when it couldn't be loaded due to full Image Memory?

----
btw. Tested on several Sony, Panasonic and Denon players.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
numberonesuperguy
Offline
Joined: 2007-05-10
Points: 0

Fact 1 is not necessarily true: Calls to gc() only recommend a garbage collection - it's a signal to the garbage collection thread to do its stuff. Its not designed so that a call to to gc() will return with more free mem (implementation dependent I expect)
But you say you wait a couple of seconds between image loads, so that should be fine!

The link you sent (thanks!) suggests all images that may need disposing of should be of type DVBBufferedImage for the very ability to call the dispose() method to manage memory appropriately on smaller-than-desktop devices.

Other than that, you could see what's returned from
Runtime.getRuntime().freeMemory()
Runtime.getRuntime().totalMemory()
Runtime.getRuntime().maxMemory()
but with memory for images set appart from heap memory, the calls may only show heap numbers. I expect that'll vary accross players - I guess software players are more likely to lump it all together.

but in actual BD-J experience I cant shed any light - I'm only a just getting past 'Hello World' (!).

elbob
Offline
Joined: 2008-10-01
Points: 0

Thanks for your answer!
Maybe we can get a discussion started on this...

As I understand the article on Image Memory Management, I can use flush() for all "normal" images and just need to use DVBBufferedImage instead of BufferedImage.
--
When writing an application, be sure that you

* Call flush() on normal images when you're done with them
* Use DVBBufferedImage instead of AWT's BufferedImage, so you can call dispose() on it when you're done
--

But I'll try...
--

With the freeMemory(), ... Methods you get the amount of Memory your App get from the VM. That's not the same thing as the available Graphics Memory. It's not that my Application is running out of Memory, I just can't load any more Images...

elbob
Offline
Joined: 2008-10-01
Points: 0

Got a hint from my guru.
I might have used MediaTracker without removing the Images after loading.
That could keep the Player from freeing my storage...
I'll check and post the outcome.

elbob
Offline
Joined: 2008-10-01
Points: 0

need to test on more players but right now it looks like it's solved:

- Images that are not removed from Media Tracker can't be flushed!

tracker.removeImage(image);
image.flush();

elbob
Offline
Joined: 2008-10-01
Points: 0

Anyone?
Is my question too stupid to be answered or is it a problem for others too :)