Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] detecting missing graphics.dispose()

I've been trying to think of a way to catch a particular bad coding
practice using aspectj.  If anyone can think of how to do it it would
be fantastic.

Description: when using a Graphics object inside a paint method, it's
common to create a copy of the object to modify.  However then it's
very important to dispose the object to free up the resources, like
this:

// good practice:
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
// do stuff
g2.dispose();
}

// bad practice:
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
// do stuff
// call to dispose missing!!
}


Can anyone see a way to catch this?


Back to the top