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

John Wagenleitner commented on GROOVY-7621:
-------------------------------------------

One problem with the test script is that it replaces the {{needsCleanup}} 
reference with a reference to a new list.  So now {{propMissing}} is still 
populating the original list passed to it and after first time through the loop 
{{needsCleanup}} is not populated with any more entries so there are no more 
calls to {{it.metaClass = null}}.  If I change it to {{needsCleanup.clear()}} 
it runs through all iterations.  Without the change it only runs 16,000 
iterations before an OOME for me.  I tested using a 1G max heap.

{code}
.....
needsCleanup.each { it.metaClass = null }
needsCleanup = []   // change to -> needsCleanup.clear()
.....
{code}



> 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