Skip to content

Commit

Permalink
8323615: PopupControl.skin.setSkin(Skin) fails to call dispose() on d…
Browse files Browse the repository at this point in the history
…iscarded Skin

Reviewed-by: angorya, mstrauss
  • Loading branch information
Marius Hanl committed Feb 1, 2024
1 parent af7e057 commit aac2df1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -213,18 +213,6 @@ public PopupControl() {
// a reference to the old value.
private Skin<?> oldValue;

@Override
public void set(Skin<?> v) {

if (v == null
? oldValue == null
: oldValue != null && v.getClass().equals(oldValue.getClass()))
return;

super.set(v);

}

@Override protected void invalidated() {
Skin<?> skin = get();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -37,7 +37,10 @@
import org.junit.Before;
import org.junit.Test;

import java.lang.ref.WeakReference;

import static org.junit.Assert.*;
import static test.com.sun.javafx.scene.control.infrastructure.ControlSkinFactory.attemptGC;

/**
*
Expand Down Expand Up @@ -650,4 +653,29 @@ private static final class PopupControlSkin<C extends PopupControl> implements S

//TODO: test computePref____ methods

/**
* Set a skin -> set another instance of the same skin (class).
*/
@Test
public void testMemoryLeakSameSkinClass() {
popup.setSkin(new PopupControlSkin<>());
Skin<?> skin = popup.getSkin();
popup.setSkin(new PopupControlSkin<>());

WeakReference<?> weakRef = new WeakReference<>(skin);
skin = null;
attemptGC(weakRef);
assertNull("Unused Skin must be gc'ed", weakRef.get());
}

@Test
public void testSetSkinOfSameClass() {
popup.setSkin(new PopupControlSkin<>());
Skin<?> oldSkin = popup.getSkin();
popup.setSkin(new PopupControlSkin<>());
Skin<?> newSkin = popup.getSkin();

assertNotEquals("New skin was not set", oldSkin, newSkin);
}

}

3 comments on commit aac2df1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinrushforth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/skara tag 23+3

@openjdk
Copy link

@openjdk openjdk bot commented on aac2df1 Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinrushforth The tag 23+3 was successfully created.

Please sign in to comment.