Reputation: 805
Without using any image loading library, I am loading images like below:
final Image img = new Image();
img.setVisible(false);
RootPanel.get().add(img);
img.addErrorHandler(new ErrorHandler() {
@Override
public void onError(ErrorEvent event) {
System.out.println(event);
}
});
img.addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
ImageElement data = ImageElement.as(img.getElement());
RootPanel.get().remove(img);
obj.setData(data);
System.out.println("Arrived:" + (System.currentTimeMillis()-startTime) + "ms");
render();
}
});
Without using RootPanel.get().add(img); the image will never be added to the DOM. So onLoad will not be triggered. But when you add the image into the DOM, if you don't remove it, this will be memory leak.
My Observations about the above code:
My questions are, are there image loading procedures (libraries) handle image loading?
Do they automatically remove the image from the DOM after the image has loaded?
Is there a more appropriate way to handle this issue where you're drawing many images but does not require the image after drawing?
Also are there fast approaches to add and remove the images to/from the DOM?
Upvotes: 4
Views: 2200
Reputation: 3025
To load images use the com.google.gwt.widgetideas.graphics.client.ImageLoader
That loads a large amount of images at one time.
Upvotes: 1