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

Bug 357072

Summary: AbstractChannel.listeners_array leaks listener instances
Product: [Tools] TCF Reporter: Anton Leherbauer <aleherb+eclipse>
Component: CoreAssignee: Project Inbox <tcf.core-inbox>
Status: RESOLVED FIXED QA Contact: Eugene Tarassov <eugene>
Severity: normal    
Priority: P3 CC: cdtdoug, mober.at+eclipse
Version: 1.0   
Target Milestone: 1.0.0   
Hardware: All   
OS: All   
Whiteboard:

Description Anton Leherbauer CLA 2011-09-08 08:31:04 EDT
The static field AbstractChannel.listeners_array is used only temporarily for notifying IChannelListeners, but this keeps those listeners from being GC'ed (until the next channel event is fired).  As listeners are often anonymous inner classes this can lead to quite serious memory leaks.
I'd suggest to clear the array after notifying the listeners.
Comment 1 Eugene Tarassov CLA 2011-09-08 14:14:06 EDT
I have both removed "static" and changed the code to clear the array when the channel is closed or a listener is removed.
Comment 2 Anton Leherbauer CLA 2011-09-09 08:05:44 EDT
There is one problem, though: If a listener removes itself when it receives onChannelClosed(), all subsequent listeners will not receive the notification because the listeners_array is cleared.
Comment 3 Eugene Tarassov CLA 2011-09-09 12:09:47 EDT
Good catch.
Looks like the original idea of reusing the array was wrong - it does not worth all the trouble. I have removed listeners_array and changed the code to create temporary array each time listeners are called.
Thanks!
Comment 4 Martin Oberhuber CLA 2011-10-04 04:57:57 EDT
It looks like this was committed to master only, but not to 0.5.0 - is this intentional?

http://git.eclipse.org/c/tcf/org.eclipse.tcf.git/commit/?id=da88b9a9263f5a97b98112dd7a600ffaf331a181
Comment 5 Eugene Tarassov CLA 2011-10-04 11:59:28 EDT
(In reply to comment #4)
> It looks like this was committed to master only, but not to 0.5.0 - is this
> intentional?

The issue looks noncritical to me, but the fix can easily be backported to 0.5.0 if anyone needs it.