Skip to content

Commit

Permalink
Cleanup leaky project classloader after code compilation
Browse files Browse the repository at this point in the history
This removes dangling references to the created widgets in ObjectUtils,
ClassUtils and MVEL.
  • Loading branch information
ptziegler committed Apr 26, 2024
1 parent 33f0ef4 commit bf6843b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.mvel2.MVEL;
import org.mvel2.ParserConfiguration;
import org.mvel2.ParserContext;
import org.mvel2.optimizers.OptimizerFactory;
import org.mvel2.optimizers.dynamic.DynamicClassLoader;
import org.mvel2.optimizers.impl.asm.ASMAccessorOptimizer;

import java.lang.reflect.Field;
import java.util.Collections;
Expand Down Expand Up @@ -168,6 +171,9 @@ public static void clearMemoryLeaks() {
public void run() throws Exception {
clearCaches(org.mvel2.util.ParseTools.class);
clearCaches(org.mvel2.PropertyAccessor.class);
if (ASMAccessorOptimizer.getMVELClassLoader() instanceof DynamicClassLoader) {
OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC);
}
}

private void clearCaches(Class<?> clazz) throws Exception {
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.wb.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.expressions,
org.eclipse.core.resources,
org.eclipse.e4.ui.css.core,
org.eclipse.ui,
org.eclipse.ui.forms,
org.eclipse.ui.editors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -468,8 +470,19 @@ protected static void openPropertyDialog(Property property) throws Exception {
// Combo property editor
//
////////////////////////////////////////////////////////////////////////////
private static final Shell TEST_COMBO_SHELL = new Shell();
private static final CCombo3 TEST_COMBO = new CCombo3(TEST_COMBO_SHELL, SWT.NONE);
private static Shell TEST_COMBO_SHELL;
private static CCombo3 TEST_COMBO;

@BeforeClass
public static void setUpAll() {
TEST_COMBO_SHELL = new Shell();
TEST_COMBO = new CCombo3(TEST_COMBO_SHELL, SWT.NONE);
}

@AfterClass
public static void tearDownAll() {
TEST_COMBO_SHELL.dispose();
}

/**
* Fill combo with items.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -11,6 +11,7 @@
package org.eclipse.wb.tests.designer.tests;

import org.eclipse.wb.core.model.ObjectInfo;
import org.eclipse.wb.core.model.ObjectInfoUtils;
import org.eclipse.wb.internal.core.DesignerPlugin;
import org.eclipse.wb.internal.core.EnvironmentUtils;
import org.eclipse.wb.internal.core.editor.DesignContextMenuProvider;
Expand All @@ -24,6 +25,7 @@
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.e4.ui.css.core.utils.ClassUtils;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
Expand Down Expand Up @@ -66,6 +68,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -104,6 +107,15 @@ public void setUp() throws Exception {
configureFirstTime();
}

@After
public void clearMemoryLeaks() throws Exception {
// ObjectInfoUtils
((Map<?, ?>) ReflectionUtils.getFieldObject(ObjectInfoUtils.class, "m_idToObjectInfo")).clear();
((Map<?, ?>) ReflectionUtils.getFieldObject(ObjectInfoUtils.class, "m_objectInfoToId")).clear();
// ClassUtils
((Map<?, ?>) ReflectionUtils.getFieldObject(ClassUtils.class, "simpleNames")).clear();
}

private void configureFirstTime() {
configureEclipseWindowLocation();
if (!m_firstDesignerTest) {
Expand Down

0 comments on commit bf6843b

Please sign in to comment.