Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Problem to free a ViewPart instance
Problem to free a ViewPart instance [message #70349] Wed, 16 January 2008 12:05 Go to next message
Eclipse UserFriend
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 #70706 is a reply to message #70349] Fri, 18 January 2008 04:14 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I finally found this :

When I do a getSite().registerContextMenu(manager,
this.openLayersMapViewer),
the registerContextMenu() method of the org.eclipse.ui.internal.PartSite
class
is executed.

This method called itself a static method named registerContextMenu() too.

It encapsulates my Menumanager object, my OpenLayersMapViewerObject and my
viewPart into a PopupMenuExtender object.

This one is then added to a the collection menuExtenders, a member of the
PartSite class.

The problem is that menuExtenders list isn't destroyed in the dispose
method of the PartSite class. (The code has been commented)

Thanks by advance for your help

Regards,

Cédric G.
Re: Problem to free a ViewPart instance [message #71196 is a reply to message #70706] Wed, 23 January 2008 05:53 Go to previous messageGo to next message
Eclipse UserFriend
Has anyone an idea to help me to fix this problem?

Thanks you very much ;)

Cédric G.
Re: Problem to free a ViewPart instance [message #71392 is a reply to message #71196] Thu, 24 January 2008 07:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------020102030206000702000009
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

C
Re: Problem to free a ViewPart instance [message #71429 is a reply to message #71392] Thu, 24 January 2008 08:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rherrmann.innoopract.com

Cedric,

thanks for the hint. As Ed Merks assumed, we added PopupMenuExtender
later and overlooked this. From what it looks right now, activating the
dispose() code solves the problem. We will do further tests and hope to
resolve this within the next days.
As already suggested, a bugzilla entry would be helpful.

Cheers,
Rüdiger

Ed Merks wrote:
> Cédric,
>
> Have you tried changing the code to this and seeing if that fixes the
> problem? It seems likely that the initial commenting out was a little
> over aggressive or that perhaps other parts were later added back and
> this was overlooked. You should probably open a bugzilla with the
> results of your experimentation...
>
> /**
> * Dispose the contributions.
> */
> public void dispose() {
> if (menuExtenders != null) {
> HashSet managers = new HashSet(menuExtenders.size());
> for (int i = 0; i < menuExtenders.size(); i++) {
> PopupMenuExtender ext = (PopupMenuExtender)
> menuExtenders.get(i);
> managers.add(ext.getManager());
> ext.dispose();
> }
> if (managers.size()>0) {
> for (Iterator iterator = managers.iterator(); iterator
> .hasNext();) {
> MenuManager mgr = (MenuManager) iterator.next();
> mgr.dispose();
> }
> }
> menuExtenders = null;
> }
>
> // if (keyBindingService != null) {
> // keyBindingService.dispose();
> // }
>
> // if (progressService != null) {
> // progressService.dispose();
> // }
>
> if (serviceLocator != null) {
> serviceLocator.dispose();
> }
> }
>
>
> Cédric G. wrote:
>> Has anyone an idea to help me to fix this problem?
>>
>> Thanks you very much ;)
>>
>> Cédric G.
>>
>>
>
Re: Problem to free a ViewPart instance [message #71483 is a reply to message #71392] Thu, 24 January 2008 09:24 Go to previous messageGo to next message
Eclipse UserFriend
Ed,

Thanks a lot for your answer.

I have tried to comment out the code you told me (located in the PartSite
class org.eclipse.rap.ui.workbench

plugin) like this :

/**
* Dispose the contributions.
*/
public void dispose() {
if (menuExtenders != null) {
HashSet managers = new HashSet(menuExtenders.size());
for (int i = 0; i < menuExtenders.size(); i++) {
PopupMenuExtender ext = (PopupMenuExtender)
menuExtenders.get(i);
managers.add(ext.getManager());
ext.dispose();
}
if (managers.size()>0) {
for (Iterator iterator = managers.iterator(); iterator
.hasNext();) {
MenuManager mgr = (MenuManager) iterator.next();
mgr.dispose();
}
}
menuExtenders = null;
}

// if (keyBindingService != null) {
// keyBindingService.dispose();
// }

// if (progressService != null) {
// progressService.dispose();
// }

if (serviceLocator != null) {
serviceLocator.dispose();
}
}

Indeed, it works well now. I have no more memory leaks when the session is
destroyed :

- The Viewer (OpenLayersMapViewer) where the contextual menu was attached
in is well destroyed.
- The Viewpart where the viewer was located in too.
- As well for the main classes of the application (I think they were
somehow bound to the previous class which could

explain why they weren't disposed) :
- CrCActionBarAdvisor
- CrCWorkbenchAdvisor
- CrCWorkbenchWindowAdvisor

Do you thinks it's only a miss ? Or commenting out this code could have
border side effects on RAP ?

OK, I'm going to notice it to bugzilla.

Thanks a lot,

Regards,

Cédric G.
Re: Problem to free a ViewPart instance [message #71576 is a reply to message #71429] Thu, 24 January 2008 10:43 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Problem to free a ViewPart instance [message #71595 is a reply to message #71576] Thu, 24 January 2008 10:51 Go to previous message
Eclipse UserFriend
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.
>
Previous Topic:Running RAP on Tomcat on Linux
Next Topic:freeing memory resources after closing the browser
Goto Forum:
  


Current Time: Thu May 08 13:01:33 EDT 2025

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

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

Back to the top