Activities do not clear references to nodes

3 views
Skip to first unread message

Mathieu

unread,
Jul 2, 2010, 7:55:35 AM7/2/10
to Piccolo2D Users
Hello,

I have been working on a project to visualize nodes a bit like the
GraphEditor example. Piccolo works well and it makes my application
look nice.
I am facing a problem. I want nodes to move, but as soon as I apply an
activity to them, something keeps the node in reference, and the node
can not be collected by the garbage collector.
I use SWT.

Here is a simple example of my problem, it is very similar to the
grapheditor example of the piccolo website.


public class GraphEditor extends PSWTCanvas {

public static void main(String[] args) {

Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(100, 150);

new GraphEditor(shell);
shell.setLayout(new GridLayout());
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

public GraphEditor(Shell shell) {
super(shell, SWT.NONE);

PLayer nodeLayer = getLayer();

final PPath node = PPath.createEllipse(20, 20, 20, 20);
nodeLayer.addChild(node);

node.animateToPositionScaleRotation(0, 0, 1, 0, 1000);
Button buttonRun = new Button(this.getShell(), SWT.None);
buttonRun.setText("Debug it");
buttonRun.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
//If we check the references of the node after clicking on the
"Debug it" button, an object of type PNode has a reference to the
node.
System.out.println(node);
}
});

}
},


I suppose I am doing things in the wrong way. I tried to set a
delagate to the activity, or remove it from the scheduler, but nothing
worked...

Could someone help me with that issue ?


Thank's a lot.


Mathieu

atdixon

unread,
Jul 24, 2010, 4:17:52 PM7/24/10
to Piccolo2D Users
This appears to be a memory leak. I'm able to reproduce it with:

http://github.com/atdixon/piccolo2d-examples/blob/master/src/main/java/atdixon/piccolo/example/ActivityMemoryLeakExample.java

The problem is that PActivityScheduler keeps a list of
"processingActivities" that it only clears when a new batch of
activities are to be executed. So if you run a bunch of activities on
a bunch of nodes just once, and then remove those nodes from the
layer, etc., they won't be gc'd b/c they will still be referenced by
private PActivityScheduler state. A workaround is to issue a "no-op"
activity after all your activities have run and you should see the
memory freed up.

Piccolo2d developers, I think the simple fix is to clear the
processingActivities list in PActivityScheduler#processActivities()
after the iteration in that method. Should I open a bug?

Michael Heuer

unread,
Aug 2, 2010, 10:20:12 AM8/2/10
to piccolo...@googlegroups.com
atdixon <atd...@gmail.com> wrote:
> This appears to be a memory leak. I'm able to reproduce it with:
>
> http://github.com/atdixon/piccolo2d-examples/blob/master/src/main/java/atdixon/piccolo/example/ActivityMemoryLeakExample.java
>
> The problem is that PActivityScheduler keeps a list of
> "processingActivities" that it only clears when a new batch of
> activities are to be executed. So if you run a bunch of activities on
> a bunch of nodes just once, and then remove those nodes from the
> layer, etc., they won't be gc'd b/c they will still be referenced by
> private PActivityScheduler state. A workaround is to issue a "no-op"
> activity after all your activities have run and you should see the
> memory freed up.
>
> Piccolo2d developers, I think the simple fix is to clear the
> processingActivities list in PActivityScheduler#processActivities()
> after the iteration in that method. Should I open a bug?

Yes, thank you.

michael

Reply all
Reply to author
Forward
0 new messages