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

Bug 358564

Summary: [Xtend][Memory Leak] Create Extensions - Possibility to clear caches.
Product: [Modeling] TMF Reporter: Christian Dietrich <christian.dietrich.opensource>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mail, sebastian.zarnekow, sven.efftinge
Version: unspecifiedFlags: sven.efftinge: indigo+
Target Milestone: SR2   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Christian Dietrich CLA 2011-09-22 08:17:14 EDT
Build Identifier: 2.0.0 2.0.1 nightly from 2011-09-21

In Xtend create extensions are cached
if i want to use them at 2 different locations i have to inject the same instance e.g. by declaring the Xtend Class singleton.

Thus i will get (if i use the same injector e.g. from an running editor)
always the same instance of the Xtend Class.

This may lead to unexpected results/memory leaks during several generator runs. (e.g. call of the "generate" action)

i'd like to be able to explicitely clear this caches e.g. by getting a clearCaches method or something like that

We currently workaround this problem by clearing the caches using reflection.

btw the builderparticipant / igenerator suffer from this "leak" too.

Reproducible: Always
Comment 1 Sven Efftinge CLA 2011-09-22 08:28:58 EDT
If you use the create extensions in a long running environment (i.e. in the IDE) you should obtain and discard a fresh instance using a Provider in order to control the lifecycle of the state.

However the ongoing refactoring will make the field visible and accessible.
Comment 2 Christian Dietrich CLA 2011-09-22 08:30:42 EDT
Good to hear,
what will be the solution for the builderparticipant/igenerator: will i have to many call the clears there too?

~Christian
Comment 3 Sven Efftinge CLA 2011-09-22 10:17:22 EDT
You should obtain a fresh instance for each transformation.
Comment 4 Christian Dietrich CLA 2011-09-22 10:26:11 EDT
since builderparticipant and its use of igenerator are infrastructure provided by xtext it is hard to do it yourself besides cleaning up manually at the end of the dogenerate method.
Comment 5 Sven Efftinge CLA 2011-09-22 10:34:35 EDT
Maybe I wasn't clear (or I misunderstood you ;-)):

I meant something like this:

class MyGenerator implements IGenerator {

  @Inject Provider<MyTransformationCode> transformerProvider

  def generate(Resoure res, IFileSystemAccess fsa) {
     transformerProvider.get().doTransformation(res, fsa)
  }

}

The lifecycle of the cache state is directly associated to the lifecycle of instances of the Xtend class containing create functions. That is how it is meant to be used.
Comment 6 Christian Dietrich CLA 2011-09-22 10:48:18 EDT
Hi,

yes this will work but i still don't know how to then solve the singleton problem:

you have Xtend class A that has a createExtension createA
and you have XtendClasses B and C that use A.createA
how to make shure that B and C get the same instance
without declaring A as Singleton.
and if a is a singleton using a provider
won't help
Comment 7 Sven Efftinge CLA 2011-09-22 10:55:54 EDT
You could
a) pass the instance around
b) marking it a singleton and explicitly clear the cache, when you think it's a good idea to do so.
Comment 8 Christian Dietrich CLA 2011-09-22 10:58:01 EDT
Thats ok for me so far - never the less it still feels like a workarround
Comment 9 Sebastian Zarnekow CLA 2011-10-12 07:28:32 EDT
The cache variable is now visible from within the Xtend class which allows to create a function that clears the cache explicitly.
Comment 10 Karsten Thoms CLA 2017-09-19 17:39:47 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 11 Karsten Thoms CLA 2017-09-19 17:51:03 EDT
Closing all bugs that were set to RESOLVED before Neon.0