[ 
https://issues.apache.org/jira/browse/GROOVY-7621?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15091664#comment-15091664
 ] 

Jochen Theodorou commented on GROOVY-7621:
------------------------------------------

Is script not a GroovyObject? Because in this case (and actually in any other 
case as well) script.metaClass = null is supposed to delete the per instance  
meta class. And if you want to use the registry... There is a 
setMetaClass(Object,MetaClass) method, which you can give a null meta class, to 
remove the per instance meta class for that object. And you could use the 
iterator to remove the per instance meta class by calling remove once you have 
reached the entry. But script.metaClass = null, and this Iterator.remove are 
both using MetaClassRegistryImpl.setMetaClass(Object,MetaClass) to remove the 
per instance meta class for a non-GroovyObject class. For a GroovyObject 
implementing class you have the meta class stored directly on that instance, 
but then of course it is collected with the instance as well

> Memory Leak (metaClassRegistry) unable to remove metaClass based on instances
> -----------------------------------------------------------------------------
>
>                 Key: GROOVY-7621
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7621
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.3.7
>         Environment: Running from Eclipse, JBoss with jdk 1.6
>            Reporter: Kimball C Sampson
>
> I'm using the GroovyScriptEngine in a web server environment where the 
> scripts are provided properties on-the-fly from database objects.  This is 
> done by implementing script.metaClass.propertyMissing.  When I return a 
> value, I set the metaClass to give the returned value even more 
> sub-properties.  After processing 100k records or so, I run out of memory.  I 
> tried to write code to remove entries from the metaClassRepository, but 
> there's no way to do it for an object instanced based metaClass.  Also, I've 
> outputed the GroovySystem.metaClassRepository.iterator().size() and it kept 
> growing.  The values are out of scope so they should get garbage collected, 
> but the metaClasses aren't getting cleaned up.
> The workaround to this problem was to implement a groovy Proxy, though, I 
> liked the metaClass solution better.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to