Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 738A117C4D for ; Tue, 2 Jun 2015 11:58:25 +0000 (UTC) Received: (qmail 47256 invoked by uid 500); 2 Jun 2015 11:58:25 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 47223 invoked by uid 500); 2 Jun 2015 11:58:25 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 47213 invoked by uid 99); 2 Jun 2015 11:58:25 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jun 2015 11:58:25 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id CC7B7181A4E for ; Tue, 2 Jun 2015 11:58:24 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.999 X-Spam-Level: X-Spam-Status: No, score=0.999 tagged_above=-999 required=6.31 tests=[KAM_LIVE=1, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 300JABIjb2Mn for ; Tue, 2 Jun 2015 11:58:14 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 3FC26428ED for ; Tue, 2 Jun 2015 11:58:14 +0000 (UTC) Received: from [192.168.1.3] ([85.180.100.113]) by mail.gmx.com (mrgmx101) with ESMTPSA (Nemesis) id 0LyR1G-1ZCM2k2vCw-015mkM for ; Tue, 02 Jun 2015 13:57:56 +0200 Message-ID: <556D9AE4.9020606@gmx.org> Date: Tue, 02 Jun 2015 14:00:36 +0200 From: Jochen Theodorou User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: users@groovy.incubator.apache.org Subject: Re: Memory leaks, GroovyClassLoader, and the MetaClassRegistry References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:nM7mY4in79o10ypEKTcTHw5ZvgbAURDnzio1yebaSRYc4qF8x6P gAI+IoYiSM0OC0AFQY00mLUWaNB+opMv/F7vCzLa10Q5qAFkgSRYgYifVy7pXfayYAmnsbf xBK9Bu6ZiG3tiyE7AFOi8uJRhGYqsPlpgMu3MuqxO8HarZlvB+33uV4QUCqBI8Qp1k27uzl GblD88RhaJzSjOKESSw1w== X-UI-Out-Filterresults: notjunk:1;V01:K0:DFpmIGxJqr8=:rZ0oDrdEdBUSOW7rLiFb6R 8vHyVJev28Sdxy7z7CcyyLb5oSKmySCtJ9jho0+CYyCqEZwBIJHs94KtzTjbGX2vdQ7hbaXz9 d8imUZHEWEPbB+x9y60+rKjMs3tfG7g20nSlRAR3e7rKyDK2toSzw7IfPTxFl+eSl6mjDGqPA gavfiKzJ7ndFWYr/gtZi9cQum4fv0xTxQ4N0KREcQgSzwiBf6mevFCqY6ypAWloQJsgBIoQIw 51LzFPl8T4XatY+wJjbm5sn/HlO8q2oBWIs+NzoNM6s1Eu+16w+4xXrRe90BGZXEpZvtnmQdN QU6Ra6CPugQeePhynl3Stpd3SVIqWal3DE7j6Lx0EjmMLsl12schFVVSaLTuUZFPLhOLbGcS6 3lfx8X0nxWDh3aFLIM2yNtUa5LSceMLw7R3DkGVShnvC6SPBhT4IF1mc6f9Rvmc2IXozNxiGx wTcH2kbp9f9G8W3QKHrtTHKKsRlzXNpQuLJh0bKTfEC7/PKLmDX0c2+ugU7ciibyT5Fx6Dt+h BnfzY97JyYtCXwrTN2Tsr0jSnxtNWaVqRayYmBosOGoJg4vBMrCbjzhrdR7HU7EmaHCcjb+V/ YmwTtN/nNil8zYO7cA1wSHoF5aRl8lYCx0DBMw04MnzDAYjV/0pTMcCIDEjQDdHoKGQojakXy zA8a+AY1hSL+XvIWKVsbbBslvxyg6Qg0dem06r5GYhExMBJUmt32wUjW3EV+RiQDKeXo= Am 01.06.2015 22:13, schrieb Kyle Boon: > We have a memory leak that I'm fairly confident that can be traced back > to this issue: > > http://stackoverflow.com/questions/14343393/using-groovyclassloader-from-java-classes-not-gcd can you tell me Groovy and Java versions as well as if you tried the vm switch -XX:+CMSClassUnloadingEnabled ? > We have a lot of REST services that result in code being compiled and > executed during the HTTP request. I'm exploring a few different options > to try to fix the memory leak by removing the class from the > MetaClassRegistry which (should) allow the class to be garbage collected > during the next full GC. At the end of the request, while there is > still an instance of the compiled Script class, I could remove the class > from the MetaClassRegistry explicitly. Or, I could create a background > job that would find all compiled Script classes and remove them from the > MetaClassRegistry in bulk. > > Complicating this slightly is that in order to reduce the number of > times we actually need to compile code, we put the compiled class into a > Guava cache. Then we can avoid the compilation step the majority of the > time. My question is, what happens if the class is removed from the > MetaClassRegistry and then another instance of that class is created > later? Would it be worth it to try to recreate the meta class for the > script class if it was missing? Or is this just a fool's errand? It really depends on what meta class you are using here... namely MetaClassImpl (default), ExpandoMetaClass or a custom one (which I assume you don't do). The default meta class handling is designed to be able to "loose" the meta class and have it automatically recreated at a later point. For this all the default meta classes are only reachable through soft references. So it is perfectly fine to remove it from the registry. It will be recreated on demand... of course that has a performance penalty. But you don't have to recreate it manually... actually setting the meta class manually can result in the meta class not being soft referenced anymore. Also groovy objects store the meta class in a instance field (groovy has per instance meta classes). So as long as the script instance exists, the meta class usually does as well, unless you null the field of course. But the instance is not the problem here I guess. If ExpandoMetaClass is used (default in Grails), things can be slightly different. Here usually strong references are used, if not from the beginning, then from the point of mutation of the meta class. Would be good to know if we can exclude the ExpandoMetaClass case. bye blackdrag -- Jochen "blackdrag" Theodorou blog: http://blackdragsview.blogspot.com/