Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Removing listeners in JFace
Removing listeners in JFace [message #294674] Wed, 16 November 2005 07:43 Go to next message
Eclipse UserFriend
Originally posted by: bernhard.xxxxxxx.xxx

When I looked at the code in some of the JFace components I came across
listeners being added to components but never removed. Like for example
in the ComboBoxCellEditor there are listeners added to the CCombo but are
never removed from the CCombo would it not cause some sort of memory leak?

code snippet of the createControl method:
comboBox.addKeyListener(new KeyAdapter() {
// hook key pressed - see PR 14201
public void keyPressed(KeyEvent e) {
keyReleaseOccured(e);
}
});

I am just wondering if this is a problem or do the listeners get disposed
once th e CCombo is disposed?
Re: Removing listeners in JFace [message #294676 is a reply to message #294674] Wed, 16 November 2005 09:01 Go to previous messageGo to next message
Markus Wolf is currently offline Markus WolfFriend
Messages: 153
Registered: July 2009
Senior Member
> When I looked at the code in some of the JFace components I came across
> listeners being added to components but never removed. Like for example
> in the ComboBoxCellEditor there are listeners added to the CCombo but
> are never removed from the CCombo would it not cause some sort of memory
> leak?
>
> code snippet of the createControl method:
> comboBox.addKeyListener(new KeyAdapter() {
> // hook key pressed - see PR 14201 public void
> keyPressed(KeyEvent e) {
> keyReleaseOccured(e);
> }
> });
>
> I am just wondering if this is a problem or do the listeners get
> disposed once th e CCombo is disposed?
>
>
If the method keyReleaseOccured() is in the same Class, then no memory
leak occurs (the listener is just a java class which needs not to
dispose something and is normally garbage collected) and the listener is
automatically removed, because if the CCombo is disposed, the list of
listeners is disposed and therefore the KeyAdapter which sends events to
the enclosing class (CCombo).

Sorry if the above is hard to get. It's not my best english :)

Markus Wolf
--
>
> emedia-solutions wolf
> Wedeler Landstrasse 63
> 22559 Hamburg
>
>> phone: (+49) 40 550 083 70
>> web: http://www.emedia-solutions-wolf.de
>> mail: markus@emedia-solutions-wolf.de
>> pgp: http://wwwkeys.de.pgp.net
>
Re: Removing listeners in JFace [message #294684 is a reply to message #294676] Wed, 16 November 2005 12:04 Go to previous message
Eclipse UserFriend
Originally posted by: Bernhard.xxxx.xxx

Markus Wolf wrote:

>> When I looked at the code in some of the JFace components I came across
>> listeners being added to components but never removed. Like for example
>> in the ComboBoxCellEditor there are listeners added to the CCombo but
>> are never removed from the CCombo would it not cause some sort of memory
>> leak?
>>
>> code snippet of the createControl method:
>> comboBox.addKeyListener(new KeyAdapter() {
>> // hook key pressed - see PR 14201 public void
>> keyPressed(KeyEvent e) {
>> keyReleaseOccured(e);
>> }
>> });
>>
>> I am just wondering if this is a problem or do the listeners get
>> disposed once th e CCombo is disposed?
>>
>>
> If the method keyReleaseOccured() is in the same Class, then no memory
> leak occurs (the listener is just a java class which needs not to
> dispose something and is normally garbage collected) and the listener is
> automatically removed, because if the CCombo is disposed, the list of
> listeners is disposed and therefore the KeyAdapter which sends events to
> the enclosing class (CCombo).

> Sorry if the above is hard to get. It's not my best english :)

> Markus Wolf

Danke fur deine antwort. Es hat mich geholfen.

Vielen Dank Markus.
Previous Topic:JVM terminated. Exit code = 1073807364
Next Topic:rcp - requirements dynamic help
Goto Forum:
  


Current Time: Thu Apr 25 00:47:56 GMT 2024

Powered by FUDForum. Page generated in 0.03260 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top