Community
Participate
Working Groups
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
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.
Good to hear, what will be the solution for the builderparticipant/igenerator: will i have to many call the clears there too? ~Christian
You should obtain a fresh instance for each transformation.
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.
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.
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
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.
Thats ok for me so far - never the less it still feels like a workarround
The cache variable is now visible from within the Xtend class which allows to create a function that clears the cache explicitly.
Closing all bugs that were set to RESOLVED before Neon.0