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

Bug 249995

Summary: [Contexts] ContextAction's leak when hiding actions sets
Product: [Eclipse Project] Platform Reporter: Chris Grindstaff <chris>
Component: UIAssignee: Paul Webster <pwebster>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: bokowski, raji
Version: 3.4Flags: bokowski: review+
Target Milestone: 3.4.2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 250133    
Attachments:
Description Flags
Context Activations v01
none
Context Activations v02 none

Description Chris Grindstaff CLA 2008-10-07 13:26:08 EDT
Looking at a heapdump of a long running RCP based application I see org.eclipse.ui.internal.contexts.SlaveContextService retaining 4MB or 8.7% of the Java heap.
Digging deeper I see there are 62,389 instances of org.eclipse.ui.internal.contexts.ContextActivation.

I think I understand why there are so many instances, I was able to "recreate" with the "RCP Mail template" example.
I changed the OpenViewAction.run method to do the following:

for (int i = 0; i < 100; i++)
	window.getActivePage().hideActionSet(getActionDefinitionId());

before running the for loop I took a look at SlaveContextService.fLocalActivations, it was size 3, which is expected.
After running this for loop twice I see 400 new instances of ContextActivation in the map.

service	org.eclipse.ui.internal.contexts.SlaveContextService  (id=58)	
	'service' referenced from:	
	fContextManagerListeners	java.util.ArrayList<E>  (id=80)	
	fDefaultExpression	org.eclipse.ui.internal.expressions.WorkbenchWindowExpression  (id=82)	
	fLocalActivations	java.util.HashMap<K,V>  (id=84)	
		[0...99]	
		[100...199]	
		[200...299]	
		[300...399]	
		[400...403]

As I understand the hideActionSet code this is expected since hideActionSet calls Perspective.removeActionSet which contains:
IContextService service = (IContextService)page.getWorkbenchWindow().getService(IContextService.class);
....
service.activateContext(ContextAuthority.DEFER_EVENTS);
service.activateContext(ContextAuthority.SEND_EVENTS);

Since the workbench window is global, and deactivateContext isn't called, these will continue to accumulate until the workbench is exited.
In the removeActionSet case it would be straightforward to deactivate in the finally block but wondered if I was misunderstanding the code.
Comment 1 Paul Webster CLA 2008-10-08 13:17:21 EDT
Created attachment 114572 [details]
Context Activations v01

A proper solution for this would be to defer events using API, but that is appropriate for 3.4.2.

I'll enter another bug for 3.5 so this can be addressed.

PW
Comment 2 Paul Webster CLA 2008-10-08 13:37:00 EDT
Could you have a quick look?

PW
Comment 3 Boris Bokowski CLA 2008-10-08 15:41:30 EDT
The patch makes sense to me, but I would like to go over it with you tomorrow.
Comment 4 Paul Webster CLA 2008-10-17 10:22:09 EDT
Created attachment 115395 [details]
Context Activations v02

Patch to cache context activations, with a test that fails without the patch.

PW
Comment 5 Paul Webster CLA 2008-10-17 12:12:15 EDT
Released for M20081022-0800
PW
Comment 6 Paul Webster CLA 2009-01-22 13:38:18 EST
In M20090121-1700
PW