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

Bug 361382

Summary: Memory leaks in profiling.ext
Product: [Modeling] M2T Reporter: Tatiana Fesenko <tatiana.fesenko>
Component: XpandAssignee: Karsten Thoms <karsten.thoms>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: karsten.thoms
Version: 1.1.0Flags: karsten.thoms: iplog+
karsten.thoms: juno+
Target Milestone: M3   
Hardware: PC   
OS: All   
Whiteboard:
Attachments:
Description Flags
Test project demonstrating the issue.
none
Proposed patch
none
Modified Test Projects
none
Patch with caching profiles none

Description Tatiana Fesenko CLA 2011-10-19 08:15:41 EDT
Created attachment 205511 [details]
Test project demonstrating the issue.

Create a transformation that applies a profile. Run it several times in the same thread - "java.lang.OutOfMemoryError: Java heap space" after approximately 30 iterations. 

I am using Eclipse Indigo with Xpand 1.1.1.

The problem is that XmiReader#load() loads profile in a new ResourceSet instead of using the resource set of the element.

I am attaching a sample project demonstrating this issue.
Comment 1 Tatiana Fesenko CLA 2011-10-19 08:35:09 EDT
Created attachment 205517 [details]
Proposed patch
Comment 2 Karsten Thoms CLA 2011-10-19 08:48:02 EDT
Created attachment 205520 [details]
Modified Test Projects

Added imported packages and org.antlr.runtime. Copied Xtend Component several times.

This way the bug got reproducable in my runtime workbench.
Comment 3 Karsten Thoms CLA 2011-10-19 09:02:50 EDT
This won't work that way, at least not generally. The transformed Model instance in your example is not attached to Resource yet when trying to apply the profile. Thus, 
  element.eResource()
will return null and raises a NullPointerException in 
  element.eResource().getResourceSet()

The element's ResourceSet can only be taken when the element is attached to a resources. Otherwise, the profile must still be loaded in its own ResourceSet.
Comment 4 Karsten Thoms CLA 2011-10-19 09:22:24 EDT
The solution is actually that the resource must be unloaded again.

	        result = (Element) r.getContents().get(0);
	        
        	// unload the resource when it was loaded in a new ResourceSet
        	// otherwise this leads to memory leak, see Bug#361382
        	r.unload();

	        return result;

Thanks for reporting and the example!
Comment 5 Tatiana Fesenko CLA 2011-10-19 09:50:49 EDT
Reopened - Java heap space after ~ 4*(70 -- number of XtendCompoments) = 280 iterations.

This issue is important while running a workflow on server, as a part of service. In that case the same workflow is executed many times with different input models.
Comment 6 Tatiana Fesenko CLA 2011-10-19 10:17:38 EDT
Created attachment 205531 [details]
Patch with caching profiles

I used "1" as a default size of HashMap assuming that in most cases the user needs only one profile.
Comment 7 Karsten Thoms CLA 2020-04-30 13:53:56 EDT
This is a batch close of open M2T Xpand bugs. It is not planned work on this component in the foreseeable future. If you think this issue needs to be solved and you plan to contribute a fix then feel free to reopen it.