Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cached EMF resources not disposed correctly #2

Open
kolovos opened this issue Nov 4, 2022 · 4 comments
Open

Cached EMF resources not disposed correctly #2

kolovos opened this issue Nov 4, 2022 · 4 comments
Labels
bug Something isn't working workaround A workaround exists for this issue

Comments

@kolovos
Copy link
Contributor

kolovos commented Nov 4, 2022

After the following ANT build file

<project default="main">
	<target name="main">
		<epsilon.emf.loadModel name="M1" modelfile="m1.ecore" metamodeluri="http://www.eclipse.org/emf/2002/Ecore" read="true" store="false"/>
		<epsilon.emf.loadModel name="M2" modelfile="m2.ecore" metamodeluri="http://www.eclipse.org/emf/2002/Ecore" read="true" store="false"/>

		<epsilon.eol>
			M1!EClass.all.first().eSuperTypes.println();
			M2!EClass.all.first().eSuperTypes.println();
			<model ref="M1"/>
			<model ref="M2"/>
		</epsilon.eol>

	</target>
</project>

is executed against the following models m1.ecore and m2.ecore that reference each other, the models are not disposed properly. As a result, if we re-execute the same build file in the same JVM, the contents of m2.ecore are not loaded from disk the second time.

<?xml version="1.0" encoding="ASCII"?>
<ecore:EClass xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmi:id="_rnSosFwLEe2eQLwPX_T8WQ" name="C11">
  <eSuperTypes href="m2.ecore#/"/>
</ecore:EClass>
<?xml version="1.0" encoding="ASCII"?>
<ecore:EClass xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmi:id="_sBzacFwLEe2eQLwPX_T8WQ" name="C221">
  <eSuperTypes href="m1.ecore#/"/>
</ecore:EClass>

A workaround for this is to add the following JavaScript task to the build file to clear the EMF driver's resource cache.

<script language="javascript">
with(new JavaImporter(org.eclipse.epsilon.emc.emf)){
  CachedResourceSet.getCache().clear();
}
</script>
@kolovos kolovos changed the title Cached EMF resources not disposed Cached EMF resources not disposed correctly Nov 4, 2022
@kolovos kolovos added the bug Something isn't working label Nov 17, 2022
@kolovos kolovos added the workaround A workaround exists for this issue label Aug 8, 2023
@arcanefoam
Copy link
Contributor

arcanefoam commented Aug 17, 2023

This also seems to happen from within Eclipse using a RunConfiguration. I am running an ETL transformation and the output Ecore model is not "unloaded" resulting in duplicate elements each time I run the transformation.

@kolovos
Copy link
Contributor Author

kolovos commented Aug 20, 2023

Until this gets properly fixed, a workaround would be to manually dispose of the problematic models using the Model Cache view.

@arcanefoam
Copy link
Contributor

If you point me to some suspects I could take a look. So far I have not been able to identify any static field or 'registry' implementations that might be causing it.

@kolovos
Copy link
Contributor Author

kolovos commented Aug 21, 2023

The culprit seems to be org.eclipse.epsilon.emc.emf.CachedResourceSet which is a global cache for EMF resources. The rationale behind this class is that if you load the same model file twice as an EmfModel, the two models will be underpinned by the same resource and therefore their EObjects will be identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working workaround A workaround exists for this issue
Projects
None yet
Development

No branches or pull requests

2 participants