Path: blob/master/test/jdk/sun/awt/image/ImageWatched/AddNoLeak.java
41155 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.image.ImageObserver;24import java.awt.image.ImageProducer;25import java.awt.image.ImageConsumer;26import java.awt.Image;27import java.awt.Container;2829/* @test 1.0 12/01/1730@bug 710415131@summary Make sure that we don't leak image observers (or related objects)32@run main/othervm AddNoLeak33@author David Buck34*/3536public class AddNoLeak {37public static void main(String[] args) {38System.setProperty("java.awt.headless", "true");39Container cont = new Container();40Image img = cont.createImage(new DummyImageSource());41for(int i=0;i < 15000;i++) {42img.getWidth(new ImageObserver() {43public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {return false;}44});45if (i % 100 == 0) {46System.gc();47}48}49}5051private static class DummyImageSource implements ImageProducer {52public void addConsumer(ImageConsumer ic){}53public boolean isConsumer(ImageConsumer ic){return false;}54public void removeConsumer(ImageConsumer ic){}55public void startProduction(ImageConsumer ic){}56public void requestTopDownLeftRightResend(ImageConsumer ic){}57}58}596061