Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022, 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 @@ -237,19 +237,6 @@ private static Class<?> loadClass(final String className, final Object instance)
// a reference to the old value.
private Skin<?> oldValue;

@Override
//This code is basically a kind of optimization that prevents a Skin that is equal but not instance equal.
//Although it's not kosher from the property perspective (bindings won't pass through set), it should not do any harm.
//But it should be evaluated in the future.
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();
// Collect the name of the currently installed skin class. We do this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022, 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 @@ -77,6 +77,40 @@ public class SkinMemoryLeakTest {

//--------- tests

/**
* default skin -> set another instance of default skin
*/
@Test
public void testMemoryLeakSameSkinClass() {
installDefaultSkin(control);
Skin<?> skin = control.getSkin();
installDefaultSkin(control);

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

@Test
public void testControlChildrenSameSkinClass() {
installDefaultSkin(control);
int childCount = control.getChildrenUnmodifiable().size();
installDefaultSkin(control);
assertEquals("Old skin should dispose children when a new skin is set",
childCount, control.getChildrenUnmodifiable().size());
}

@Test
public void testSetSkinOfSameClass() {
installDefaultSkin(control);
Skin<?> oldSkin = control.getSkin();
installDefaultSkin(control);
Skin<?> newSkin = control.getSkin();

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

/**
* default skin -> set alternative
*/
Expand Down