Skip to main content



      Home
Home » Eclipse Projects » e(fx)clipse » Cleaning up controller instances attached to MParts in an E4 application(A controller instance attached to an E4 MPart remains in memory when the MPart was removed from the model)
Cleaning up controller instances attached to MParts in an E4 application [message #1268503] Mon, 10 March 2014 11:40 Go to next message
Eclipse UserFriend
Hi,

when I build an E4 application with multiple MParts in the application model, I can rely on Eclipse's DI mechanism to create and destroy the contribution objects associated with these MParts. This means that, if I a put an event handling method like this:

@Inject
@Optional
void handleEvent(@UIEventTopic("MyTopic") Event event) {
   // handle event here
}


into the contribution class of an MPart, the method will not be called to handle "MyTopic" events after the MPart is removed from the application model.

But I have noticed that this clean-up does not work for an event handling method in the controller class of a JavaFX view that is attached as a child to the root pane of the contribution class of an MPart, like this:

@PostConstruct
public void init(BorderPane pane, @FXMLLoader FXMLLoaderFactory loaderFactory) {
   final FXMLBuilder<Node> builder = loaderFactory.loadRequestorRelative("View.fxml");
   try {
      final Node node = builder.load();
      pane.setCenter(node);
   } catch (IOException e) {
      // 
   }
}


When the MPart is removed from the application model and a "MyTopic" event is sent, the controller's handleEvent method will be called, whereas the same method in the contribution object will not. At this point, the JavaFX view could have been removed from memory and destroyed, along with its controller, as their MPart container does not exist anymore.

Is this something e(fx)clipse should take care of? Or do I need to take care of it myself? Are there any best practices for this type of memory clean-up?

Thanks,
Uwe
Re: Cleaning up controller instances attached to MParts in an E4 application [message #1268612 is a reply to message #1268503] Mon, 10 March 2014 14:47 Go to previous messageGo to next message
Eclipse UserFriend
There should be nothing for you to clean up.

I'm currently at loss why the control is not detached because the
containing context should have been disposed so I need to track this
down in my sample app.

Tom

On 10.03.14 16:40, Uwe San wrote:
> Hi,
>
> when I build an E4 application with multiple MParts in the application
> model, I can rely on Eclipse's DI mechanism to create and destroy the
> contribution objects associated with these MParts. This means that, if I
> a put an event handling method like this:
>
>
> @Inject
> @Optional
> void handleEvent(@UIEventTopic("MyTopic") Event event) {
> // handle event here
> }
>
>
> into the contribution class of an MPart, the method will not be called
> to handle "MyTopic" events after the MPart is removed from the
> application model.
>
> But I have noticed that this clean-up does not work for an event
> handling method in the controller class of a JavaFX view that is
> attached as a child to the root pane of the contribution class of an
> MPart, like this:
>
>
> @PostConstruct
> public void init(BorderPane pane, @FXMLLoader FXMLLoaderFactory
> loaderFactory) {
> final FXMLBuilder<Node> builder =
> loaderFactory.loadRequestorRelative("View.fxml");
> try {
> final Node node = builder.load();
> pane.setCenter(node);
> } catch (IOException e) {
> // }
> }
>
>
> When the MPart is removed from the application model and a "MyTopic"
> event is sent, the controller's handleEvent method will be called,
> whereas the same method in the contribution object will not. At this
> point, the JavaFX view could have been removed from memory and
> destroyed, along with its controller, as their MPart container does not
> exist anymore.
>
> Is this something e(fx)clipse should take care of? Or do I need to take
> care of it myself? Are there any best practices for this type of memory
> clean-up?
>
> Thanks,
> Uwe
Re: Cleaning up controller instances attached to MParts in an E4 application [message #1268636 is a reply to message #1268612] Mon, 10 March 2014 15:32 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

There's a general problem with event unsubscription I can even get
events for parts although the context is disposed.

I can remember having a discussion with Oleg 2 years ago because the
unsubscribing relies on the GC which is not reliable.

I filed an upstream bug [1] so that this gets fixed in the e4 project -
you can force the clean up by doing a System.gc() which really can't be
the correct solution.

Tom

[1]https://bugs.eclipse.org/bugs/show_bug.cgi?id=430041

On 10.03.14 19:47, Tom Schindl wrote:
> There should be nothing for you to clean up.
>
> I'm currently at loss why the control is not detached because the
> containing context should have been disposed so I need to track this
> down in my sample app.
>
> Tom
>
> On 10.03.14 16:40, Uwe San wrote:
>> Hi,
>>
>> when I build an E4 application with multiple MParts in the application
>> model, I can rely on Eclipse's DI mechanism to create and destroy the
>> contribution objects associated with these MParts. This means that, if I
>> a put an event handling method like this:
>>
>>
>> @Inject
>> @Optional
>> void handleEvent(@UIEventTopic("MyTopic") Event event) {
>> // handle event here
>> }
>>
>>
>> into the contribution class of an MPart, the method will not be called
>> to handle "MyTopic" events after the MPart is removed from the
>> application model.
>>
>> But I have noticed that this clean-up does not work for an event
>> handling method in the controller class of a JavaFX view that is
>> attached as a child to the root pane of the contribution class of an
>> MPart, like this:
>>
>>
>> @PostConstruct
>> public void init(BorderPane pane, @FXMLLoader FXMLLoaderFactory
>> loaderFactory) {
>> final FXMLBuilder<Node> builder =
>> loaderFactory.loadRequestorRelative("View.fxml");
>> try {
>> final Node node = builder.load();
>> pane.setCenter(node);
>> } catch (IOException e) {
>> // }
>> }
>>
>>
>> When the MPart is removed from the application model and a "MyTopic"
>> event is sent, the controller's handleEvent method will be called,
>> whereas the same method in the contribution object will not. At this
>> point, the JavaFX view could have been removed from memory and
>> destroyed, along with its controller, as their MPart container does not
>> exist anymore.
>>
>> Is this something e(fx)clipse should take care of? Or do I need to take
>> care of it myself? Are there any best practices for this type of memory
>> clean-up?
>>
>> Thanks,
>> Uwe
>
Re: Cleaning up controller instances attached to MParts in an E4 application [message #1269109 is a reply to message #1268636] Tue, 11 March 2014 07:52 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your feedback and your analysis, Tom. I'll track the bug you opened.
Re: Cleaning up controller instances attached to MParts in an E4 application [message #1269813 is a reply to message #1269109] Wed, 12 March 2014 04:10 Go to previous messageGo to next message
Eclipse UserFriend
My advice until would be use the IEventBroker instead until this stuff
is resolved, the IEventBroker is cleaned also automatically when the
IEclipseContext is disposed so you also don't have to think about
unsubscribing!

Tom

On 11.03.14 12:52, Uwe San wrote:
> Thanks for your feedback and your analysis, Tom. I'll track the bug you
> opened.
Re: Cleaning up controller instances attached to MParts in an E4 application [message #1270011 is a reply to message #1268503] Wed, 12 March 2014 07:59 Go to previous message
Eclipse UserFriend
Good to know, we'll use that option instead.
Previous Topic:Problem running E4/e(fx)clipse on iMac
Next Topic:Fitting a dialog to the size of its content
Goto Forum:
  


Current Time: Mon Apr 28 01:01:14 EDT 2025

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

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

Back to the top