|
-
Mar 15th, 2012, 04:30 PM
#1
Thread Starter
New Member
Memory leak(?)
Hello people,
I'm quite a newbie with Java, so please bear with me (and tips are very much appreciated).
I've started working on a program that is solely run from the system tray and it seems to work to a certain extent.
Now I'm not entirely sure, but I think the program has a memory leak, because mousing over the system tray icon results in increased memory usage (in task manager).
Here's my code:
Code:
public class PopNotifyInstance implements ActionListener {
private MenuItem manageItem;
private MenuItem exitItem;
public void InitPopNotify() {
final TrayIcon trayIcon;
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("src/popnotify/img/tray_icon.png");
PopupMenu popup = new PopupMenu();
manageItem = new MenuItem("Manage notifications");
popup.add(manageItem);
manageItem.addActionListener(this);
popup.addSeparator();
exitItem = new MenuItem("Quit");
popup.add(exitItem);
exitItem.addActionListener(this);
trayIcon = new TrayIcon(image, "PopNotify", popup);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("TrayIcon could not be added.");
}
} else {
// System tray disabled
System.err.println("System tray disabled.");
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof MenuItem) {
MenuItem j = (MenuItem) e.getSource();
System.out.println(j.getLabel() + " button was pressed.");
if (j.getLabel().equals("Quit")) {
System.exit(0);
} else if (j.getLabel().equals("Manage notifications")) {
//TODO add functionality
}
}
}
public static void main(String[] args) {
PopNotifyInstance popnotify = new PopNotifyInstance();
popnotify.InitPopNotify();
}
}
So my question is; what causes my application to use more memory when I mouseover the system tray icon?
Thanks in advance,
LENJ
Last edited by LENJ; Mar 15th, 2012 at 04:47 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|