Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Unable to delete Commands
Unable to delete Commands [message #793792] Wed, 08 February 2012 10:21 Go to next message
Eclipse UserFriend
Hi,

I am generating GMF diagram programatically.
I am creating the gmf symbols programatically by creating CreateViewRequest first and then creating by diagramEditPart.getCommand(createRequest);

Then i am executing the command using
diagramEditPart.getDiagramEditDomain().getDiagramCommandStack()
.execute(createCommand);

I am unable to dispose these commands,i am able to see the these commads even after calling command.dispose().

After completed diagram file is generated even the EditParts and EditPart figure also present in the Heap memory,see the attached JProfiler Report.

I am not opening/closing the diagram file at any point of time during my diagram generation.I am creating the gmf file using OffscreenEditPartFactory.

Can anyone Help me in this issue.
  • Attachment: Commands.JPG
    (Size: 236.96KB, Downloaded 217 times)
Re: Unable to delete Commands [message #793797 is a reply to message #793792] Wed, 08 February 2012 10:27 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

what is the path to GC root of your command instance?
I suppose that it is retained by the CommandStack.
So you can limit the size of the stack or try to clean it.

Regards,
Re: Unable to delete Commands [message #794276 is a reply to message #793797] Thu, 09 February 2012 00:03 Go to previous messageGo to next message
Eclipse UserFriend
how can i clean the commandStack,i tried using commandStack.flush but with no effect.
Re: Unable to delete Commands [message #795482 is a reply to message #794276] Fri, 10 February 2012 09:16 Go to previous messageGo to next message
Eclipse UserFriend
Can anyone help please,
I am creating a compound command

org.eclipse.gef.commands.CompoundCommand command = new org.eclipse.gef.commands.CompoundCommand("Add Symbol Data");

AbstractTransactionalCommand createCommand = null;
for (SymbolHolder prevNode : prevNodes) {
createCommand = new CustomCommand();
command.add(new ICommandProxy(createCommand));
}
then i am executing using

org.eclipse.gef.commands.CommandStack cs = rootEditPart
.getDiagramEditDomain().getDiagramCommandStack();
cs.execute(command);

After execution i have called

command.dispose();

and iterated through createcommands and called dipose on them.
I even called cs.flush();
but when i inspect the OperationHistoryFactory.getOperationHistory() in undo command List i am seeing all the commands.


My Custom Command classe look like this



public class SetAttributesCommand extends AbstractTransactionalCommand {

public SetAttributesCommand(TransactionalEditingDomain editingDomain,DiagramEditPart diagramEditPart) {
super(diagramEditPart.getEditingDomain(), "Set attributes", null);

}


protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {

////////////Custom Logic///////////////
return CommandResult.newOKCommandResult();
}



@Override
public void dispose() {
super.dispose();

}
}
Re: Unable to delete Commands [message #797433 is a reply to message #795482] Mon, 13 February 2012 08:32 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

It is unclear why do you want to call dispose at the first place.

To my understanding, this method is intended to be called by the CommandStack of limited size, when it pushes the command out of itself. This is the way to tell you that it is safe to release the resources aquired in the command, so you are only expected to implement it, not to explicitly call it.
Note the javadoc of Command#dispose() that states:
	/**
	 * This is called to indicate that the <code>Command</code> will not be used
	 * again. The Command may be in any state (executed, undone or redone) when
	 * dispose is called. The Command should not be referenced in any way after
	 * it has been disposed.
	 */

and this is clearly not your case because the command stack still references it.

What is the high level effect you are trying to achieve?

Regards,
Michael "Borlander" Golubev
at Montages Think Tank, Prague, Czech Republic
Montages AG, Zürich, Switzerland
Re: Unable to delete Commands [message #797477 is a reply to message #797433] Mon, 13 February 2012 09:40 Go to previous messageGo to next message
Eclipse UserFriend
Hello!

I want to add 2 separate points.

1. It is always better to push the composite changes as a single ICommandProxy on top of compositeTransactionalCommand comparing to use 1 gef CompositeCommand holding multiple separate ICommandProxy. So, instead of
CompositeCommand gedComposite = new ..
gefComposite.add(new ICommandProxy(createICommand1()));
gefComposite.add(new ICommandProxy(createICommand2()));
gefComposite.add(new ICommandProxy(createICommand3()));
return gefComposite;

use:
CompositeTransactionalCommand iComposite = new ...
iComposite.add(createICommand1());
iComposite.add(createICommand2());
iComposite.add(createICommand3());
return new ICommandProxy(iComposite);

This way if user executes an undo, you will avoid diagram update during the possibly inconsistent state between ICommand3 and ICommand2 and between ICommand2 and ICommand1

2. If you want to prevent the diagram user from undoing your programmatic change, just push the no-op gef Command with canUndo() {return false;} after pushing your actual command

Regards,
Svyatoslav Kovalsky
at Montages Think Tank, Prague, Czech Republic
Montages AG, Zürich, Switzerland
Re: Unable to delete Commands [message #799586 is a reply to message #797477] Wed, 15 February 2012 22:45 Go to previous messageGo to next message
Eclipse UserFriend
Hi Svyatoslav Kovalsky,

Your points did the trick.Now my custom Commands are getting garbage collected.

But in Heap i still have the reference to DiagramGraphicalViewer,all EditParts and Figures are present can you help me in understanding why they are not garbage collected.

how can i dispose them?


My execution steps are
1)open my Custom Editor

2)Click on generateGMFDiagram(i am using OffscreenEditPartFactory to create file,i.e i am not opening GMF File at any point of time)
3)After execution i am deactivating my RootEditPart and making my diagramResource reference as null)

But still the DiagramGraphicalViewer,EditParts and Figures are present in Heap memory.

Re: Unable to delete Commands [message #799741 is a reply to message #799586] Thu, 16 February 2012 04:01 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

with OffscreenEditPart, can you try to create your own new Shell and dispose it after the execution

Regards,
Re: Unable to delete Commands [message #800696 is a reply to message #799741] Fri, 17 February 2012 06:15 Go to previous message
Eclipse UserFriend
Thanks Aurelien Pupier for your help.i am able to dispose editParts now.

[Updated on: Fri, 17 February 2012 06:16] by Moderator

Previous Topic:Looking for a GEF tutorial ...
Next Topic:links in compartments
Goto Forum:
  


Current Time: Thu Jul 10 06:10:01 EDT 2025

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

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

Back to the top