Bug 397302 - AbstractSourceProvider.removeSourceProviderListener causes memory leak in many cases
Summary: AbstractSourceProvider.removeSourceProviderListener causes memory leak in man...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: 4.3 M7   Edit
Assignee: Paul Elder CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2013-01-02 05:41 EST by Stefan Folkesson CLA
Modified: 2013-04-30 11:10 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Folkesson CLA 2013-01-02 05:41:50 EST
When adding listeners to AbstractSourceProvider, it stores the listeners in an array.

removeSourceProviderListener removes a listener from its position in the array and compacts the array but the compacting algorithm results in an extra copy of the last listener in the array.

Example: Let's say there are two listeners A and B.
1. The listener array will be [A,B,null,null,null,null,null] and listenerCount will be 2.

2. Now someone calls removeSourceProviderListener(A). The compacting algorithm will result in the following listener array [B,B,null,null,null,null,null]. listenerCount will be set to 1.

3. Now someone calls removeSourceProviderListener(B). This will result in the following listener array [null,B,null,null,null,null,null].

Note that the array still refers to B even though we requested the listener to be removed.
Comment 1 John Arthorne CLA 2013-01-03 10:34:27 EST
Great find!
Comment 2 Paul Elder CLA 2013-04-08 12:10:40 EDT
Pushed proposed fix & unit test to Gerrit:
https://git.eclipse.org/r/11729
Comment 4 Paul Elder CLA 2013-04-30 11:10:58 EDT
Verified in 4.3.0.I20130430-0031