Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 318262

Summary: STEM heap allocation keeps increasing over time
Product: [Technology] STEM Reporter: Stefan Edlund <sedlund>
Component: CoreAssignee: Stefan Edlund <sedlund>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mattadav
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Mac OS X   
Whiteboard:

Description Stefan Edlund CLA 2010-06-28 19:25:45 EDT
I notice that just working in the designer perspective creating new graphs and building scenarios, the allocated heap keeps increasing (make sure you enable 'Show  Heap Status' in the preferences), and even focing the GC won't free up memory. It goes to the point where > 1 GB of memory is used.

Java 6 has a jmap utility that can force a hprof heap dump that we can import into the Eclipse Memory Analyzer to find leak suspects.

Just a quick test doing that I notice lots of URI objects inside a URICache, as well as STEM Models and Graphs in memory. There is really no reason to keep this in memory, and the project explorer seems partly responsible. 

Anyway, this will require some more serious investigation to fix.
Comment 1 Stefan Edlund CLA 2010-06-29 21:03:24 EDT
I've tracked down the main memory leak to the org.eclipse.emf.common.util.URI$URICache that can actually grow REALLY large since:

1. Every URI that is created ends up in this cache
2. We create lots of unnecessary  URI's in STEM that are just thrown away.
3. The URICache is using weak reference values to allow for garbage collection, but the keys in the cache are not cleaned up until a limit is reached (1000 initially) and the limit keeps growing larger and larger if you create lots of URIs.

One problem is that in STEM we create URI's in the constructor of IndentifiableImp. The constructor is called when EMF is deserializing any identifiable (Nodes, Edges, Graphs...) and the value we set in the constructor is overwritten but still ends up in the URI cache.

The fix is to not call setURI in the constructors of STEM identifiables, but higher up in the call stack only when necessary. This change will affect many places in STEM so we need to carefully test the code after fixing.
Comment 2 James Kaufman CLA 2010-07-09 18:29:04 EDT
Stefan is working on the fix. Should be in by August 1.
Comment 3 James Kaufman CLA 2010-07-09 18:48:29 EDT
*** Bug 311295 has been marked as a duplicate of this bug. ***
Comment 4 Matthew Davis CLA 2010-07-10 12:18:43 EDT
Adding myself to CC
Comment 5 Stefan Edlund CLA 2010-07-26 18:57:38 EDT
A fix has been checked in that does the following:

1. Gets rid of the automatic generation of a URI for identifiables, nodes and edges in the constructor of those classes. Instead a URI is generated and set by the class that creates new instances of nodes, edges and identifiables. This way we avoid generating and tossing away lots of uncessecary URIs when deserializing EMF objects.

2. A big memory hog was the project explorer. It calls Utility.getIdentifiable(...) and inside that method a new resource set was created each time, so we did not take advantage of the caching provided by that class. Now there's a single resource set that's reused to support caching of resources. One complication is that resources in the resource set needs to be marked modified whenever a "child" resource is modified. For instance, a scenario needs to be refreshed if a containing model is updated (or a sub-model of a model etc.). In the IdentifiableContentProvider and the visit method, we get a callback whenever a resource is modified in the editors. We now check and mark other resources that needs to be reloaded due to the update. 

3. The GraphItemProvider automatically sorted alphabetically its children in the getChildren() method. This can be very expensive for large graphs having lots of nodes, edges and labels. I took out the sorting and it greatly improved the performance when editing large graphs. If we feel that we need to support sorting of children, we can revisit this and figure out how to be smarter about the sorting.
Comment 6 Stefan Edlund CLA 2010-07-28 16:54:38 EDT
I will mark this fixed for now, but might re-open it (or create a new one) if we find that the solution is not enough or that it's causing other unexpected behavior.
Comment 7 James Kaufman CLA 2011-07-18 19:46:59 EDT
Complete