Hi there,
from first glance there seems to be nothing wrong with your code. I think
with IE7/8 there was an issue with the cache control that properly, does the
leak still exists when removing the cache controls?
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache");
- Daniel Kurka
2010/11/1 hermis <[email protected]>
> Hello,
>
> I have written a simple application which fills a FlexTable with a set
> of images. There is a timer which updates the URL of each image every
> second. The URL points to a Servlet which in turn generates a random
> PNG image on its doGet() method and writes it to the response output
> stream. The servlet sets the "Cache-Control" header to "No-Cache".
>
> When I run the webapp in IE7 / 8 the memory gradually increases.
> Leaving it overnight can get it close to 1Gb.
>
> Here is the client code:
>
> #################################################################
>
> public class LeakyApp implements EntryPoint
> {
> public static final String IMAGE_SERVLET_NAME = "imageServlet";
>
> public void onModuleLoad()
> {
> leak();
> }
>
> private void leak()
> {
> UrlBuilder urlBuilder = createUrlBuilder();
>
> final FlexTable table = new FlexTable();
>
> final List<Image> lstImages = createAndAddImages(5,10 ,table
> );
>
> final String strURL = urlBuilder.buildString();
>
> final Timer timer = new Timer(){
>
> int nCounter = 0;
>
> @Override
> public void run()
> {
> for (Image img : lstImages)
> {
> img.setUrl( strURL + "?" +
> nCounter++) ;
> }
> }
> };
>
> final Button btnStartLeak = new Button("Leak");
> btnStartLeak.addClickHandler( new ClickHandler()
> {
> @Override
> public void onClick(ClickEvent event)
> {
> RootPanel.get().remove( btnStartLeak );
> RootPanel.get().add( table );
> timer.scheduleRepeating( 1000 );
> }
> });
>
> RootPanel.get().add( btnStartLeak );
> }
>
> private List<Image> createAndAddImages(int rowCount, int colCount,
> FlexTable table)
> {
> List<Image> lstImages = new ArrayList<Image>();
>
> for(int row = 0; row<rowCount; row++)
> {
> for(int col = 0; col<colCount; col++)
> {
> Image image = new Image();
> lstImages.add( image );
> table.setWidget(row, col, image);
> }
> }
>
> return lstImages;
> }
>
> private UrlBuilder createUrlBuilder()
> {
> UrlBuilder urlBuilder = null;
>
> if( GWT.isScript() )
> {
> urlBuilder = new UrlBuilder();
> urlBuilder.setHost( Window.Location.getHost() );
> urlBuilder.setPath( Window.Location.getPath() +
> IMAGE_SERVLET_NAME );
> }
> else
> {
> urlBuilder = Window.Location.createUrlBuilder();
> urlBuilder.setPath( IMAGE_SERVLET_NAME );
> }
>
> return urlBuilder;
> }
> }
>
> ############################################################
>
> Here is the servlet code:
>
> ############################################################
>
> public class ImageServlet extends HttpServlet
> {
> private int nCounter = 0;
> private Font font = new Font("Tahoma", Font.BOLD, 10);
>
> private static Color getRandomColor()
> {
> int r = (int)(Math.random()* 255);
> int g = (int)(Math.random()* 255);
> int b = (int)(Math.random()* 255);
>
> return new Color(r,g,b);
> }
>
> @Override
> protected void doGet ( HttpServletRequest request,
> HttpServletResponse response ) throws IOException
> {
>
> OutputStream out = response.getOutputStream();
>
> response.setContentType("image/png");
> response.addHeader("Pragma", "no-cache");
> response.addHeader("Cache-Control", "no-cache");
>
> ImageIO.write( generateRandomImage(), "png", out );
>
> out.close();
> }
>
> private BufferedImage generateRandomImage()
> {
> return generateRandomImage(80, 80);
> }
>
> private BufferedImage generateRandomImage(int width, int height)
> {
> BufferedImage image = new BufferedImage(width, height,
> BufferedImage.TYPE_INT_ARGB);
>
> Graphics2D g2d = image.createGraphics();
> g2d.setFont( font );
> g2d.setColor( getRandomColor() );
> g2d.fillRect(0, 0, width, height);
> g2d.setColor( Color.WHITE );
> g2d.drawString("" + nCounter, 20, 20);
>
> System.err.println(" img " + nCounter );
>
> nCounter++;
>
> if( nCounter == Integer.MAX_VALUE )
> nCounter = 0;
>
> return image;
> }
> }
>
> ############################################################
>
> Is there a programming error, or is it the nature of what the
> application is doing causing the memory leak? Can anyone explain what
> is happening behind the scenes?
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.