|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
28 | 28 | import com.sun.javafx.scene.control.VirtualScrollBar;
|
29 | 29 | import com.sun.javafx.scene.control.behavior.ListCellBehavior;
|
30 | 30 | import com.sun.javafx.tk.Toolkit;
|
| 31 | +import java.lang.ref.WeakReference; |
31 | 32 | import java.util.ArrayList;
|
32 | 33 | import java.util.Arrays;
|
33 | 34 | import java.util.Collections;
|
@@ -1975,4 +1976,28 @@ public void testEventIndicesOnSelectRange() {
|
1975 | 1976 | assertEquals("List item at index 1 should be selected", 1, (int) sm.getSelectedIndices().get(0));
|
1976 | 1977 | assertEquals("List item at index 2 should be selected", 2, (int) sm.getSelectedIndices().get(1));
|
1977 | 1978 | }
|
| 1979 | + |
| 1980 | + @Test |
| 1981 | + public void testListViewLeak() { |
| 1982 | + ObservableList<String> items = FXCollections.observableArrayList(); |
| 1983 | + WeakReference<ListView<String>> listViewRef = new WeakReference<>(new ListView<>(items)); |
| 1984 | + attemptGC(listViewRef, 10); |
| 1985 | + assertNull("ListView has a leak.", listViewRef.get()); |
| 1986 | + } |
| 1987 | + |
| 1988 | + private void attemptGC(WeakReference<ListView<String>> weakRef, int n) { |
| 1989 | + for (int i = 0; i < n; i++) { |
| 1990 | + System.gc(); |
| 1991 | + System.runFinalization(); |
| 1992 | + |
| 1993 | + if (weakRef.get() == null) { |
| 1994 | + break; |
| 1995 | + } |
| 1996 | + try { |
| 1997 | + Thread.sleep(50); |
| 1998 | + } catch (InterruptedException e) { |
| 1999 | + fail("InterruptedException occurred during Thread.sleep()"); |
| 2000 | + } |
| 2001 | + } |
| 2002 | + } |
1978 | 2003 | }
|
0 commit comments