Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Disposing a MenuManager
Disposing a MenuManager [message #1746097] Fri, 21 October 2016 15:36 Go to next message
Magnus Konze is currently offline Magnus KonzeFriend
Messages: 7
Registered: November 2014
Junior Member
Hi,

it seems that my application has a memory leak.
After viewing an heapdump with Eclipse Memory Analyser i think i found the problem:

There is a composite, which can be opened (=create a new one) and closed (=dispose). The composite has a ToolBar. Here is a snippet of that code:
MenuManager menuManager = new MenuManager(...);
ToolBar toolBar = new ToolBar(this...);
ToolItem toolItem = new ToolItem(toolBar...);
toolItem.addSelectionListener(new SelectionAdapter() {
	public void widgetSelected(SelectionEvent e) {
		final Menu menu = menuManager.createContextMenu(toolBar);
		...
		menu.setVisible(true);
	}
});


I have to dispose the MenuManager myself, because it's not a child of my composite, right?

But what is the correct way?
JavaDoc for MenuManager.dispose() says:
Quote:
Disposes of this menu manager and frees all allocated SWT resources. Notifies all contribution items of the dispose. Note that this method does not clean up references between this menu manager and its associated contribution items. Use {@link #removeAll()} for that purpose, but note that will not dispose the items.


Do i have to call both?
This seems to solve my memory problem:
parent.addDisposeListener(new DisposeListener() {
	public void widgetDisposed(final DisposeEvent e) {
		menuManager.dispose();
		menuManager.removeAll();
	}
});
Re: Disposing a MenuManager [message #1746174 is a reply to message #1746097] Mon, 24 October 2016 13:25 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2277
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
is it better to do it other way round: first removeAll and then dispose?
Regards,
Ivan
Re: Disposing a MenuManager [message #1746192 is a reply to message #1746174] Mon, 24 October 2016 20:23 Go to previous messageGo to next message
Chris Fairhall is currently offline Chris FairhallFriend
Messages: 197
Registered: February 2011
Senior Member
If you called removeAll first, none of the contribution items would have their dispose method called.
Re: Disposing a MenuManager [message #1746204 is a reply to message #1746192] Tue, 25 October 2016 07:18 Go to previous messageGo to next message
Magnus Konze is currently offline Magnus KonzeFriend
Messages: 7
Registered: November 2014
Junior Member
Chris Fairhall wrote on Mon, 24 October 2016 20:23
If you called removeAll first, none of the contribution items would have their dispose method called.

Yes, those contribution items have to be disposed too. So the order of those calls was on purpose.

So, do you think my approach ist correct?
Re: Disposing a MenuManager [message #1746325 is a reply to message #1746204] Thu, 27 October 2016 02:50 Go to previous message
Chris Fairhall is currently offline Chris FairhallFriend
Messages: 197
Registered: February 2011
Senior Member
I don't see why you need to remove the items after disposing the menu manager.

If it's the disposed MenuManager that is keeping the items from being garbage collected, why are you keeping a reference to it? What is holding on to the MenuManager? Do you re-use it after disposing it?
Previous Topic:Why in rap are missing shellIconified and shellDeiconified events ?
Next Topic:Theming on CTabFolder
Goto Forum:
  


Current Time: Fri May 25 05:38:51 GMT 2018

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

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

Back to the top