Skip to main content

Some questions about PhoneME

5 replies [Last post]
fivecat
Offline
Joined: 2007-02-07
Points: 0

1. QtImage uses Vector to store ImageObserver references, not WeakReference. So when applications release all references of certain ImageObserver, the ImageObserver object can't be collected by GC, unless the Image Object is released. But, there may be some other modules using the Image. It makes memory leak, doesn't it? (You should know, when observing a GIF, imageUpdate method may always return true. And, WeakReference is used in J2SE)

2. When using Toolkit.getImage() to get a cached GIF, it does NOT animate? (This is another difference from J2SE)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Hinkmond Wong

Hi Fivecat,

phonemeadvanced@mobileandembedded.org wrote:
> 1. QtImage uses Vector to store ImageObserver references, not
> SoftReference. So when applications release all references of certain
> ImageObserver, the ImageObserver object can't be collected by GC,
> unless the Image Object is released. But, there may be some other
> modules using the Image. It makes memory leak, isn't it? (You should
> know, when observing a GIF, imageUpdate method may always return
> true. And, SoftReference is used in J2SE)

It's not technically a memory leak if other modules still need to use
the Image object. Since other modules depend on the Image object to be
around, it cannot be garbage collected. It is only a memory leak if all
other modules also release the Image Object and it is not garbage
collected at that time of release by all others.

> 2. When using Toolkit.getImage() to get a cached GIF, it does NOT
> animate? (This is another difference from J2SE) [Message sent by

Animated GIF images work fine in phoneME Advanced. What is your
testcase? I have seen animated GIF images working fine using phoneME
Advanced on Qt/Embedded 2.3.10 on a Linux/XScale (MontaVista) cell phone
device.

> 3. How can I release a GIF object?
>
> //testing
>
> import java.awt.Image;
> import java.awt.Toolkit;
> import java.awt.image.ImageObserver;
> import java.io.IOException;
>
> public class TestObserver implements ImageObserver {
> public static void main(String[] args) {
> Image img = Toolkit.getDefaultToolkit()
> .createImage("D:\\temp\\images\\a.gif");
> img.getWidth(new TestObserver());
> try {
> System.in.read();
> System.in.skip(2);
> img = null;
> // The Observer always get notices
>
> System.in.read();
> } catch (IOException ex) {
> ex.printStackTrace();
> }
> }
>
> public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
> if(infoflags == this.ALLBITS){
> System.out.println("ALLBITS");
> }
> if(infoflags == this.FRAMEBITS){
> System.out.println("FRAMEBITS");
> }
> return true;
> }
> }
>
>

You might need to use img.flush()

See:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Image.html#flush()

Hinkmond

> forum member 'fivecat' (fivecat)]

> http://forums.java.net/jive/thread.jspa?messageID=202457
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: advanced-unsubscribe@phoneme.dev.java.net
> For additional commands, e-mail: advanced-help@phoneme.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: advanced-unsubscribe@phoneme.dev.java.net
For additional commands, e-mail: advanced-help@phoneme.dev.java.net

fivecat
Offline
Joined: 2007-02-07
Points: 0

Hi Mr. Wong, thanks for replying.

>> 1. QtImage uses Vector to store ImageObserver references, not
>> WeakReference. So when applications release all references of certain
>> ImageObserver, the ImageObserver object can't be collected by GC,
>> unless the Image Object is released. But, there may be some other
>> modules using the Image. It makes memory leak, doesn't it? (You should
>> know, when observing a GIF, imageUpdate method may always return
>> true. And, WeakReference is used in J2SE)

> It's not technically a memory leak if other modules still need to use
> the Image object. Since other modules depend on the Image object to be
> around, it cannot be garbage collected. It is only a memory leak if all
> other modules also release the Image Object and it is not garbage
> collected at that time of release by all others.

I know it's not a technical memory leak. But it may lead to memory waste. The ImageObserver objects cannot be garbage collected while users have no way to get the observers' references. Specially, if an image is often cached by the Toolkit for reusing, it may accumulate too many observers.
In my case, I release some GIFs from a component in its finalize method. The component is also an observer of these images. It works fine on J2SE, but not on PhoneME, because the component can't be finalized unless the images are release.

>> 2. When using Toolkit.getImage() to get a cached GIF, it does NOT
>> animate? (This is another difference from J2SE) [Message sent by

> Animated GIF images work fine in phoneME Advanced. What is your
> testcase? I have seen animated GIF images working fine using phoneME
> Advanced on Qt/Embedded 2.3.10 on a Linux/XScale (MontaVista) cell phone
> device.

The problem was resolved. I used another way to release GIF images to instead of flush(), what made mistake.

Hinkmond Wong

phonemeadvanced@mobileandembedded.org wrote:
> Hi Mr. Wong, thanks for replying.
>
>>> 1. QtImage uses Vector to store ImageObserver references, not
>>> SoftReference. So when applications release all references of certain
>>> ImageObserver, the ImageObserver object can't be collected by GC,
>>> unless the Image Object is released. But, there may be some other
>>> modules using the Image. It makes memory leak, isn't it? (You should
>>> know, when observing a GIF, imageUpdate method may always return
>>> true. And, SoftReference is used in J2SE)
>
>> It's not technically a memory leak if other modules still need to
>> use the Image object. Since other modules depend on the Image
>> object to be around, it cannot be garbage collected. It is only a
>> memory leak if all other modules also release the Image Object and
>> it is not garbage collected at that time of release by all others.
>
> I know it's not a technical memory leak. But it may lead to memory
> waste. The ImageObserver objects cannot be garbage collected while users
> has no way to get the observers' references. Specially, if an image is
> always cached by the Toolkit for reusing, it may accumulate too many
> observers.
>
> In my case, I release some GIFs from a component in its finalize
> method. The component is also an observer of these images. It works fine
> on J2SE, but not on PhoneME, because the component can't be finalized
> unless the images are release.

I see what you mean that this could still pose a problem. And, it
should be easily solved if a SoftReference is used instead of a Vector,
like you suggested. Do you mind if I take your info and submit a bug?

Or, if you'd like, you can submit a bug using IssueTracker at this link:

https://phoneme.dev.java.net/servlets/ProjectIssues
(Make sure to log in by clicking on the "Login" link to see the "Enter:
Defect" active link to create a new bug report).

After clicking, Enter: "Defect", you can select "me-personal-basis",
with subcategory "classes_awt" for this bug.

Let me know if you need any help.

>>> 2. When using Toolkit.getImage() to get a cached GIF, it does NOT
>>> animate? (This is another difference from J2SE) [Message sent by
>
>
>> Animated GIF images work fine in phoneME Advanced. What is your
>> testcase? I have seen animated GIF images working fine using phoneME
>> Advanced on Qt/Embedded 2.3.10 on a Linux/XScale (MontaVista) cell phone
>> device.
>
> The problem was resolved. I used another way to release GIF images to instead of flush(), what made mistake.

I'm glad you found a way to make it work!

Hinkmond

---------------------------------------------------------------------
To unsubscribe, e-mail: advanced-unsubscribe@phoneme.dev.java.net
For additional commands, e-mail: advanced-help@phoneme.dev.java.net

fivecat
Offline
Joined: 2007-02-07
Points: 0

Thanks for your friendliness and patience.
About the bug report, if you could help, that would be wonderful.

Hinkmond Wong

Hi Fivecat,

phonemeadvanced@mobileandembedded.org wrote:
> Thanks for your friendliness and patience.
> About the bug report, if you could help, that would be wonderful.

I have entered a bug report using the phoneME IssueTracker as Issue #7.
Please see:

https://phoneme.dev.java.net/issues/show_bug.cgi?id=7

Thanks for pointing out that problem! Hopefully we will have a fix for
the next release.

Hinkmond

---------------------------------------------------------------------
To unsubscribe, e-mail: advanced-unsubscribe@phoneme.dev.java.net
For additional commands, e-mail: advanced-help@phoneme.dev.java.net