Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Compile-time errors

Title: RE: [aspectj-users] Compile-time errors

Hi Hugo
I don't know of any way to make a compile time aspect that will do what you want (very interested to know if one of the experts knows of a way!). Without knowing the control flow of your application, I don't see how any static compile time view would work, I mean methods A, B and C could all add listeners, with no remove, but be ok if the control flow always comes back to method D which removes the listeners. Likewise method Q could have calls to both add and remove but depending on context (ordering and conditional execution) could add a listener that never gets removed.

Can you come up with a pointcut that defines "when it is appropriate" to remove the listener? Then just have the aspect define advice to remove any dangling listeners at that point. If you don't want the aspect in your production code, you could use the aspects you defined below to dynamically keep track of who added and removed listeners, and have the "appropriate" pointcut generate logging/debugging info to identify the culprits who added the listeners that didn't get removed.

Good luck!
Elizabeth

-----Original Message-----
From: Hugo Magalhães [mailto:Hugo.Magalhaes@xxxxxxxxxxx]
Sent: Thursday April 10, 2003 11:14 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Compile-time errors


Good afternoon.

It's possible to create an compile time Aspect to see if each listener added to a model is also removed from the model when appropried? The reason for this is that our application has memory leaks due to the fact that not all of our listeners are removed when appropried, and because it's an application with a considerable amount of code, this type of Aspect could be a great help in finding those lost listeners.

I´ve created an Aspect with two pointcuts that catch all methods that add listeners to a model and all that remove listeners but they work independently. Is there any way to put them to work together?

The code is the following:

----------------------------------------------

- Aspect:

1.  public aspect EventCallListener {
2.                             
3.  pointcut addListenerCall(Object model, java.util.EventListener listener)
4.       : call(void *.add*Listener(java.util.EventListener+))
5.       && target(model) && args(listener);
6.             
7.  pointcut removeListenerCall(Object model, java.util.EventListener listener)
8.       : call(void *.remove*Listener(java.util.EventListener+))
9.       && target(model) && args(listener);
10.            
11. declare error: addListenerCall(Object, java.util.EventListener)
12.      : "Listener added";
13.            
14. declare error: removeListenerCall(Object, java.util.EventListener)
15.      : "Listener removed";
16                     
17. }

-----------------------------------------------

Thanks in advance,
Hugo Magalhães



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top