Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Memory leak in Ecore application (Ecore resources are not removed from heap)
Memory leak in Ecore application [message #1816893] Mon, 11 November 2019 09:29 Go to next message
Iñaki Berriotxoa is currently offline Iñaki BerriotxoaFriend
Messages: 5
Registered: February 2019
Junior Member
Hi all,

I am having a memory issue with my RCP application and I am not able to locate it.

Let's see. I have an RCP application where users model the structure of an Application. Later on, based on the user input, the I generate some other intermediate models to finally generate code.

Before I start the transformation process I create a ResourceSet and I load all the required models in there.

ResourceSet resourceSet = new ResourceSetImpl();
File definitionFile = new File(filePath);
Resource resource = resourceSet.getResource(URI.createFileURI(definitionFile.getAbsolutePath()), true);
Definition definition = (SwDefinition) resource.getContents().get(0);


During the transformation process, I create some objects to manage this transformation. This objects are the responsibles to create the intermediate ecore resources that will allow to finally generate code.

I have been analyzing with MAT and JavaVisualVM, and this is the conclusion. When the transformation process is finished, the manager objects I create for transformation are deleted, but it looks like the ecore resources I create during this process are not deleted from heap (even if I call the GarbageCollector after the transformation) , and somehow something is pointing to these objects. I am not able to locate what is pointing to this resources.

What am I doing wrong?
Does anybody have a clue about what could be happening?
Can somebody explain how ecore saves the resources in memory?

Thanks in advance


Re: Memory leak in Ecore application [message #1816895 is a reply to message #1816893] Mon, 11 November 2019 11:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30700
Registered: July 2009
Senior Member
There's no way to answer such a question from a relatively superficial description. To track down memory leaks I've always used YourKit, and it helps identify exactly how any specific object is reachable from some "GC root". Such "GC root" analysis is the only way to know why any specific object is retained in the heap. There is of course nothing intrinsic in EMF that will retain a resource set or a resource in the heap permanently. If you're specifically using Ecore resources, the same is true, but of course it's possible that you have manually (somewhere in your code) added an EPackage to EPackage.Registry.INSTANCE and that's definitely a GC root that would permanently keep in the heap any Ecore model you've put in the map. This is why a resource set has its own package registry so that one can register models locally to the resource set such that they can be garbage collected when the resource set is garbage collected.

If the tools you are using can't help you identify exactly the path(s) to the GC root(s) for any specific object, then it's probably worth investing in YourKit because that's definitely capable of finding such things.
Re: Memory leak in Ecore application [message #1816898 is a reply to message #1816895] Mon, 11 November 2019 12:35 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6540
Registered: July 2009
Senior Member
Hi

The EMF objects typically form a very highly cross-connected graph and so if there is any external reference to any object in the graph, everything is locked into memory and identifying the external reference is very hard. Because of global registries and Adapters it is very easy for something to be referenced from a static. Each Resource should be explicitly unloaded to provide opportunities for adapters to clean up. Since adapters are involved, it is very easy for contributions from the wider EMF eco-system to be imperfectly coded and to cause what appears to be an 'EMF' problem.

I recommend that your shut down code sets everything you can access to null, and clears lists. Then you will have something that you can consider debugging.

Beware, make sure that your debugging tool is not the cause of further residual references by ensuring that local variables are nulled and that you return to one level higher up the stack.

Xtext provides a helpful org.eclipse.xtext.testing.GlobalRegistries class that may be used to reset EMF registries, but AFAIAA the update for the EAnnotationValidator.Registry is still pending so you may prefer org.eclipse.ocl.examples.test.xtext.GlobalRegistries2.

Regards

Ed Willink
Re: Memory leak in Ecore application [message #1816905 is a reply to message #1816898] Mon, 11 November 2019 14:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30700
Registered: July 2009
Senior Member
Debugging is not the way to find memory leaks because it doesn't help to find incoming references. Theorizing the source of the leak is also unlikely to be fruitful. Unloading a resource set's resources might help, but it might just be expensive and pointless. It's simply best to use a tool (like YourKit) that will show you the shortest path to a GC root and on that path you will find the cause of the problem.
Re: Memory leak in Ecore application [message #1816908 is a reply to message #1816905] Mon, 11 November 2019 16:30 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6540
Registered: July 2009
Senior Member
HI

Absolutely, debugging alone is almost useless in the face of hard leaks.

I use the debugger to set the context for VisualVM to show the GCRoot paths. (I'm still waiting for YourKIt to give me a license.)

Regards

Ed Willink
Re: Memory leak in Ecore application [message #1816964 is a reply to message #1816895] Wed, 13 November 2019 06:56 Go to previous message
Iñaki Berriotxoa is currently offline Iñaki BerriotxoaFriend
Messages: 5
Registered: February 2019
Junior Member
Thanks a lot! I will take a look on YourKit. I don't manually add any EPackage to EPackage.Registry.INSTANCE, so I will have to check deeper in the heap analysis.

Thanks for your answer,

Iñaki
Previous Topic:Run Eclipse Epsilon code generation online
Next Topic:ArchiveUrlConnection and Performance
Goto Forum:
  


Current Time: Mon Dec 16 12:19:47 GMT 2019

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

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

Back to the top