Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » Item Providers causing memory Leak?
Item Providers causing memory Leak? [message #676932] Tue, 07 June 2011 02:22 Go to next message
Samantha Chan is currently offline Samantha ChanFriend
Messages: 60
Registered: July 2009
Member
Hi,

I have created a table view based on an EMF model.

In my view, I have a label provider that extends from AbstractFactoryLabelProvider. I have a custom implementation of the content provider that does not extend from AbstractFactoryContentProvider. I passed a ComposedAdapterFactory to the label provider, so eventually it delegates to my model's item provider to retrieve labels and images. I believe this is pretty standard.

My model is updated every 3 seconds. When the model is refreshed, we remove one instance of a model object, and add a new one in. The view is updated correctly to show these changes.

We expect that when the object is removed from our model, the object is no longer referenced by anything and it should be garbage collected.

However, we have noticed that this is not the case, We found that none of the model objects are cleaned up after they are removed. I tracked it down to the item provider for the object. Our item providers are singleton, so we have one item provider for each model type. When the label provider attempts to retrieve label, the AdapterFactoryLabelProvider calls the AdapterFactory to adapt the object to its item provider. Everytime this method gets called, eventually the object's item provider is called to add the "notifier" to a "target" list. - via ItemProviderAdapter.setTarget. However, the object is never removed from the item provider when it is removed from the model. (ItemProviderAdapter.unsetTarget is never called.) As a result, our model objects are never garbage collected, and eventually we run out of memory.

My question is... when are the notifiers supposed to be removed from the ItemProviderAdapter's target list? Is this removal handled automatically when the object is removed from the model (via some notification?) If not, what is the best way of removing these references?

Thanks for your help.
Samantha
(no subject) [message #677132 is a reply to message #676932] Tue, 07 June 2011 16:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Smantha,

Please use the eclipse.tools.emf newsgroup/forum for questions about EMF.

More comments below.

Samantha Chan wrote:
> Hi,
>
> I have created a table view based on an EMF model.
>
> In my view, I have a label provider that extends from
> AbstractFactoryLabelProvider. I have a custom implementation of the
> content provider that does not extend from
> AbstractFactoryContentProvider. I passed a ComposedAdapterFactory to
> the label provider, so eventually it delegates to my model's item
> provider to retrieve labels and images. I believe this is pretty
> standard.
Yep.
>
> My model is updated every 3 seconds. When the model is refreshed, we
> remove one instance of a model object, and add a new one in.
Remove meaning?
> The view is updated correctly to show these changes.
>
> We expect that when the object is removed from our model, the object
> is no longer referenced by anything and it should be garbage collected.
The item providers are adapters that are attached to your objects. They
are not automatically removed.
>
> However, we have noticed that this is not the case, We found that
> none of the model objects are cleaned up after they are removed. I
> tracked it down to the item provider for the object. Our item
> providers are singleton, so we have one item provider for each model
> type. When the label provider attempts to retrieve label, the
> AdapterFactoryLabelProvider calls the AdapterFactory to adapt the
> object to its item provider. Everytime this method gets called,
> eventually the object's item provider is called to add the "notifier"
> to a "target" list. - via ItemProviderAdapter.setTarget. However,
> the object is never removed from the item provider when it is removed
> from the model. (ItemProviderAdapter.unsetTarget is never called.) As
> a result, our model objects are never garbage collected, and
> eventually we run out of memory.
The item provider has no way of knowing what 'removed from your model"
means. Even if you delete an object in the editor, you could undo the
change so the object isn't removed at all...
>
> My question is... when are the notifiers supposed to be removed from
> the ItemProviderAdapter's target list?
When the adapter factory is disposed, it removes the adapters from all
the adapted objects.
> Is this removal handled automatically when the object is removed
> from the model (via some notification?)
No.
> If not, what is the best way of removing these references?
Depending on what's easier for you, you might just call
eObject.eAdapters().clear() on the removed object(s), or you might
dispose the factory and create new ones. (Note that if you unload a
resource, all the adapters on all the contained objects are cleared.)
> Thanks for your help.
> Samantha


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: (no subject) [message #692660 is a reply to message #677132] Tue, 05 July 2011 00:34 Go to previous messageGo to next message
phisco123  is currently offline phisco123 Friend
Messages: 3
Registered: July 2011
Junior Member
Ed Merks wrote on Tue, 07 June 2011 12:36
Smantha,

Please use the eclipse.tools.emf newsgroup/forum for questions about EMF.

More comments below.

Samantha Chan wrote:
> Hi,
>
> I have created a table view based on an EMF model.
>
> In my view, I have a label provider that extends from
> AbstractFactoryLabelProvider. I have a custom implementation of the
> content provider that does not extend from
> AbstractFactoryContentProvider. I passed a ComposedAdapterFactory to
> the label provider, so eventually it delegates to my model's item
> provider to retrieve labels and images. I believe this is pretty
> standard.
Yep.
>
> My model is updated every 3 seconds. When the model is refreshed, we
> remove one instance of a model object, and add a new one in.
Remove meaning?
> The view is updated correctly to show these changes.
>
> We expect that when the object is removed from our model, the object
> is no longer referenced by anything and it should be garbage collected.
The item providers are adapters that are attached to your objects. They
are not automatically removed.
>
> However, we have noticed that this is not the case, We found that
> none of the model objects are cleaned up after they are removed. I
> tracked it down to the item provider for the object. Our item
> providers are singleton, so we have one item provider for each model
> type. When the label provider attempts to retrieve label, the
> AdapterFactoryLabelProvider calls the AdapterFactory to adapt the
> object to its item provider. Everytime this method gets called,
> eventually the object's item provider is called to add the "notifier"
> to a "target" list. - via ItemProviderAdapter.setTarget. However,
> the object is never removed from the item provider when it is removed
> from the model. (ItemProviderAdapter.unsetTarget is never called.) As
> a result, our model objects are never garbage collected, and
> eventually we run out of memory.
The item provider has no way of knowing what 'removed from your model"
means. Even if you delete an object in the editor, you could undo the
change so the object isn't removed at all...
>
> My question is... when are the notifiers supposed to be removed from
> the ItemProviderAdapter's target list?
When the adapter factory is disposed, it removes the adapters from all
the adapted objects.
> Is this removal handled automatically when the object is removed
> from the model (via some notification?)
No.
> If not, what is the best way of removing these references?
Depending on what's easier for you, you might just call
eObject.eAdapters().clear() on the removed object(s), or you might
dispose the factory and create new ones. (Note that if you unload a
resource, all the adapters on all the contained objects are cleared.)
> Thanks for your help.
> Samantha


Hey Ed...

Man I know that this si not the right forum to post this, but I was looking for you, I really need to ask you something...

I saw a topic called
"Getting RoleSets from xmi files - EPF" by Quentin ... and you were one of the guys who seems to know a lot about it...

So, here's the thing... when this Guy
Quentin says:

" I can list all the roles from my EPF Composer model, I can also list all the tasks and phases, as well as the work products, etc."

How can he do it???... I mean, I tried to do it with the same code that he posted but it doesn't work:

ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.getResource(fileURI,true);
for (Iterator i = resource.getAllContents(); i.hasNext() {
Object o = i.next();
if (o instanceof Task) {
Task ta = (Task)o;
System.out.println(" - Role : " + ta.getPresentationName());
}

It doesn't even read the xmi.. It doesn't get in it...

So, would you help me with this... or if you have a code example of how to do it, that would be awsome...

I really need to get the info(task, roles...) from the xmi file

Ok, that' all, I hope you can help me..

Thanks a lot...
Re: (no subject) [message #693011 is a reply to message #692660] Tue, 05 July 2011 15:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Can't you ask the EPF folks how to read their model? If you're running
stand alone, you'll need to register a resource factory for the file
extension you're trying to read. You've read the introductory EMF
overview article, particularly the section about saving and loading
resources?


> Ed Merks wrote on Tue, 07 June 2011 12:36
>> Smantha,
>>
>> Please use the eclipse.tools.emf newsgroup/forum for questions about
>> EMF.
>>
>> More comments below.
>>
>> Samantha Chan wrote:
>> > Hi,
>> >
>> > I have created a table view based on an EMF model.
>> >
>> > In my view, I have a label provider that extends from >
>> AbstractFactoryLabelProvider. I have a custom implementation of the
>> > content provider that does not extend from >
>> AbstractFactoryContentProvider. I passed a ComposedAdapterFactory to
>> > the label provider, so eventually it delegates to my model's item >
>> provider to retrieve labels and images. I believe this is pretty >
>> standard.
>> Yep.
>> >
>> > My model is updated every 3 seconds. When the model is refreshed,
>> we > remove one instance of a model object, and add a new one in.
>> Remove meaning?
>> > The view is updated correctly to show these changes.
>> >
>> > We expect that when the object is removed from our model, the
>> object > is no longer referenced by anything and it should be garbage
>> collected.
>> The item providers are adapters that are attached to your objects.
>> They are not automatically removed.
>> >
>> > However, we have noticed that this is not the case, We found that
>> > none of the model objects are cleaned up after they are removed. I
>> > tracked it down to the item provider for the object. Our item >
>> providers are singleton, so we have one item provider for each model
>> > type. When the label provider attempts to retrieve label, the >
>> AdapterFactoryLabelProvider calls the AdapterFactory to adapt the >
>> object to its item provider. Everytime this method gets called, >
>> eventually the object's item provider is called to add the "notifier"
>> > to a "target" list. - via ItemProviderAdapter.setTarget. However,
>> > the object is never removed from the item provider when it is
>> removed > from the model. (ItemProviderAdapter.unsetTarget is never
>> called.) As > a result, our model objects are never garbage
>> collected, and > eventually we run out of memory.
>> The item provider has no way of knowing what 'removed from your
>> model" means. Even if you delete an object in the editor, you could
>> undo the change so the object isn't removed at all...
>> >
>> > My question is... when are the notifiers supposed to be removed
>> from > the ItemProviderAdapter's target list?
>> When the adapter factory is disposed, it removes the adapters from
>> all the adapted objects.
>> > Is this removal handled automatically when the object is removed
>> > from the model (via some notification?) No.
>> > If not, what is the best way of removing these references?
>> Depending on what's easier for you, you might just call
>> eObject.eAdapters().clear() on the removed object(s), or you might
>> dispose the factory and create new ones. (Note that if you unload a
>> resource, all the adapters on all the contained objects are cleared.)
>> > Thanks for your help.
>> > Samantha
>
>
> Hey Ed...
> Man I know that this si not the right forum to post this, but I was
> looking for you, I really need to ask you something...
>
> I saw a topic called
> "Getting RoleSets from xmi files - EPF" by Quentin ... and you were
> one of the guys who seems to know a lot about it...
>
> So, here's the thing... when this Guy Quentin says:
>
> " I can list all the roles from my EPF Composer model, I can also list
> all the tasks and phases, as well as the work products, etc."
>
> How can he do it???... I mean, I tried to do it with the same code
> that he posted but it doesn't work:
>
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = resourceSet.getResource(fileURI,true);
> for (Iterator i = resource.getAllContents(); i.hasNext() {
> Object o = i.next();
> if (o instanceof Task) {
> Task ta = (Task)o;
> System.out.println(" - Role : " + ta.getPresentationName());
> }
>
> It doesn't even read the xmi.. It doesn't get in it...
>
> So, would you help me with this... or if you have a code example of
> how to do it, that would be awsome...
>
> I really need to get the info(task, roles...) from the xmi file
>
> Ok, that' all, I hope you can help me..
>
> Thanks a lot...
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:How to merge distributed model data? (ecore+xmi)
Next Topic:how to use uuid as data type in a classs
Goto Forum:
  


Current Time: Tue Apr 16 13:37:07 GMT 2024

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

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

Back to the top