Problem to free a ViewPart instance [message #70349] |
Wed, 16 January 2008 12:05  |
Eclipse User |
|
|
|
Hi,
I'm actually using Optimizeit to find memory leak in a RAP based
application.
The application is composed of three viewpart, but one of them is causing
a problem :
Each time, I refresh the browser, I see in Optimizeit, a new instance of
this viewpart have been created. But the old one isn't catched by the
garbage collector.
Contrary to the two others viewPart.
It seems this event occur because I have added a context menu to this view
part. Because when I remove the context menu, this works well.
Here the code of the viewpart, I create with the creation of the context
menu :
//---------------------------------------------------------- ------------
public class CartographyViewpart extends ViewPart {
/**
* Widget displaying the OpenLayers map.
*/
private OpenLayersMapViewer openLayersMapViewer = null;
/**
* MenuManager instance used to support contextual menus on the
cartographic
* map.
*/
private MenuManager manager = null;
/**
* The context menu listener
*/
private ContextMenuListener contextMenuListener = new
ContextMenuListener();
/**
* Constructor
*/
public CartographyViewpart() {
}
/**
* Method used to fill the data into the panel parent : parent panel
where
* we add the data
*/
// @SuppressWarnings("restriction")
public void createPartControl(final Composite parent) {
// A grid (one column as layout)
GridLayout gridLayout = new GridLayout(1, false);
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
parent.setLayout(gridLayout);
// Cartographic area creation
composite = new Composite(parent, SWT.BORDER);
composite.setLayout(gridLayout);
openLayersMapViewer = new OpenLayersMapViewer(composite, SWT.NONE);
FormatTools.fillComposite(openLayersMapViewer.getControl(), SWT.FILL,
SWT.FILL, true, true);
FormatTools.fillComposite(composite, SWT.FILL, SWT.FILL, true, true);
hookContextMenu();
}
/**
* Hook a contextual menu to the cartographic map.
*/
private void hookContextMenu() {
manager = new MenuManager("#PopupMenu1"); //$NON-NLS-1$
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(contextMenuListener);
Menu menu = manager.createContextMenu(this.openLayersMapViewer
.getControl());
openLayersMapViewer.getControl().setMenu(menu);
getSite().registerContextMenu(manager, this.openLayersMapViewer);
}
/**
* Fill the contextual menu with actions.
*
* @param manager
* The menu manager
*/
private void fillContextMenu(IMenuManager manager) {
ISelection selection = this.openLayersMapViewer.getSelection();
if (selection == null)
return;
if (selection instanceof IStructuredSelection) {
StructuredSelection objects = (StructuredSelection) selection;
Iterator<ModelObject> iter = objects.iterator();
while (iter.hasNext()) {
final ModelObject modelObject = iter.next();
Action action = new Action(modelObject.getName()) {
public void run() {
ModelObjectSelection.getInstance()
.setSelectedModelObject(modelObject);
}
};
manager.add(action);
}
}
}
/**
* {@inheritDoc}
*/
public void dispose() {
super.dispose();
manager.removeMenuListener(contextMenuListener);
manager.dispose();
manager = null;
contextMenuListener = null;
openLayersMapViewer=null;
}
/**
* Class used to listen to selection changes on zoom menu items.
*
* @author TRS
*
*/
private class ContextMenuListener implements IMenuListener2 {
/**
* {@inheritDoc}
*/
public void menuAboutToHide(IMenuManager manager) {
}
/**
* {@inheritDoc}
*/
public void menuAboutToShow(IMenuManager manager) {
fillContextMenu(manager);
}
}
}
//---------------------------------------------------------- -------------
The context menu works well, but is there something i missed in the
dispose method as an example().
It seems the problem come from the ViewSite class where my context menu is
registered in a list as a PopupMenuExtender object but this list isn't
destroy in the ViewSite dispose method. Is there a way to unregister it ?
Thanks for yours answers,
Regards,
Cédric G.
|
|
|
|
|
|
|
|
|
Re: Problem to free a ViewPart instance [message #71595 is a reply to message #71576] |
Thu, 24 January 2008 10:51  |
Eclipse User |
|
|
|
Originally posted by: rherrmann.innoopract.com
Thanks Cedric, the bug entry is fine.
Cédric G. wrote:
> Rüdiger,
>
> I have reported this problem in bugzilla, but i'm not sure if it has
> been well recorded.
> Could you tell me if it is Ok ?
>
> Regards,
>
> Cédric G.
>
|
|
|
Powered by
FUDForum. Page generated in 0.08137 seconds