Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 310361

Summary: Some Stdlib-Extensions cause memory leaks
Product: [Modeling] M2T Reporter: Jochen Schmich <jochen.schmich>
Component: XpandAssignee: Karsten Thoms <karsten.thoms>
Status: CLOSED WONTFIX QA Contact:
Severity: major    
Priority: P3 CC: karsten.thoms, sebastian.zarnekow, sven.efftinge
Version: unspecifiedKeywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Bug Depends on:    
Bug Blocks: 361452    

Description Jochen Schmich CLA 2010-04-24 04:18:35 EDT
ElementPropertiesExtensions:
contains a field: private static Map<Object, Map<String,Object>> outerMap = null;
This field is causing a memory leak in long-running applications that call this extension in the same VM.

CounterExtensions:
private static java.util.Map vars;

I introduced shutdown()-methods that clear those static HashMaps right after the workflow has been completed.
Comment 1 Sven Efftinge CLA 2010-05-20 03:30:09 EDT
A contribution (patch) would be most welcome :-)
I've exemplary fixed this for the counter extension. I think most of these things could be handled using the same base class.
Comment 2 Jochen Schmich CLA 2010-05-20 03:39:38 EDT
Sorry, can't contribute a patch that fast - my company firewall keeps my from checking out the source code.
Comment 3 Jochen Schmich CLA 2010-05-20 03:51:16 EDT
Well... i'll try it this way to contribute my hacks:

public class CounterExtensions {
	
	private static int globalCounter = 0;
	private static Map<Object,Integer> vars = new HashMap<Object,Integer>();

	...	
	
	public static void shutdown() {
		if(vars != null) {
			vars.clear();
		}
	}

}


public class ElementPropertiesExtensions {

	private static Map<Object, Map<String,Object>> outerMap = null;
	
	...
		
	public static void shutdown() {
		if(outerMap != null) {
			outerMap.clear();	
			outerMap = null;
		}
	}
	
}
Comment 4 Jochen Schmich CLA 2010-05-20 03:53:06 EDT
The other way would change the visibility of the static fields, to enable a subclass to clear the Maps...
Comment 5 Jochen Schmich CLA 2010-05-26 11:58:47 EDT
Thanks for fixing the CounterExtensions -> and thanks for introducing a better solution than my hacks were! Going to test against the current Build.
Comment 6 Karsten Thoms CLA 2012-08-09 06:30:05 EDT
Also these classes are affected:
- GlobalVarExtensions
- PropertiesExtensions
- TraceComponent
- UIDHelper
Comment 7 Karsten Thoms CLA 2012-08-09 08:34:53 EDT
Fixed:
- ElementPropertiesExtensions
- GlobalVarExtensions
- UIDHelper
by extending AbstractStatefulExtension


PropertiesExtensions and TraceComponent remain. The problem is here that data is exchanged between the Workflow Component and the extensions. There is currently no way to access the WorkflowContext from an extension class. Also the ExecutionContext cannot be used.
Comment 8 Karsten Thoms CLA 2012-11-19 04:14:33 EST
For ElementPropertiesExtensions it is necessary to support the static map for storage as an alternative, since a major customer project is unfortunately relying on the fact that properties are preserved over multiple workflow executions.

Therefore this class will get a legacy mode, which has to be enabled by invoking ElementPropertiesExtensions.setLegacyMode(true). If legacy mode is enabled, the static map gets instantiated and storage of properties will go there. If set to 'false', the map is removed again. This also enables to clean up the memory that the static storage causes. This way also legacy code can avoid the memory leak.
Comment 9 Karsten Thoms CLA 2012-11-28 03:34:16 EST
ElementPropertiesExtension legacy mode introduced with commit# 1611cc2f47d064646bf098facc1e4156a4e537a7
Comment 10 Karsten Thoms CLA 2013-01-15 09:41:35 EST
For backward compatibility legacy mode must be added for the other refactored extension classes also (i.e. GlobalVarExtensions, PropertiesExtensions).
Comment 11 Sebastian Zarnekow CLA 2013-08-12 06:58:06 EDT
The commit from comment #7 broke backwards compatibility with existing clients. Any reason why the API tooling of Eclipse is not used for Xpand?
Comment 12 Karsten Thoms CLA 2013-08-12 15:00:44 EDT
API tooling was set up recently, after that time.
Comment 13 Sebastian Zarnekow CLA 2013-08-12 15:04:36 EDT
(In reply to comment #12)
> API tooling was set up recently, after that time.

That's unfortunate, but a copy'n paste of the old code allowed to fix the existing projects. Not too nice, but probably not a show-stopper.

I suggest to close this ticket rather than leaving it in the ASSIGNED state any longer.
Comment 14 Karsten Thoms CLA 2013-08-12 15:57:03 EDT
There are still components that cause memory leaks (esp. TraceComponent). And with the current code base it is not possible to fix these components. I would like to close this ticket, but this would just mean I would have to open another one for the remaining components.
Comment 15 Karsten Thoms CLA 2020-04-30 13:53:32 EDT
This is a batch close of open M2T Xpand bugs. It is not planned work on this component in the foreseeable future. If you think this issue needs to be solved and you plan to contribute a fix then feel free to reopen it.