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

Bug 318820

Summary: EclipseContext does unnecessary object allocations
Product: [Eclipse Project] Platform Reporter: Stefan Mücke <s.muecke>
Component: RuntimeAssignee: Project Inbox <e4.runtime-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: bokowski, ob1.eclipse, pwebster, remy.suen
Version: 3.7   
Target Milestone: 4.1   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Proposed patch for EclipseContext.dispose() ob1.eclipse: iplog+

Description Stefan Mücke CLA 2010-07-04 16:25:14 EDT
Created attachment 173380 [details]
Proposed patch for EclipseContext.dispose()

EclipseContext does unnecessary object allocations.

I found this problem when I wanted to create a temporary EclipseContext as follows:

IEclipseContext context = EclipseContextFactory.create();
// ... set some values
context.set(key, value);
context.setParent(parentContext);
// ... do something with the context
context.dispose();

I expected that creating a context without a parent and setting some values should be a cheap operation. But, even though there are no listeners installed on the context, there is a lot of overhead when the context is changed.

For example, the EclipseContext.dispose() method will always create a HashSet, an EclipseContext[]-array, and a Computation[]-array regardless of whether there are listeners.
Comment 1 Oleg Besedin CLA 2010-07-06 10:19:00 EDT
Nice catch, thanks Stefan!

Patch applied to CVS Head.