Return-Path: Delivered-To: apmail-lucene-lucene-net-dev-archive@www.apache.org Received: (qmail 76782 invoked from network); 7 May 2010 23:42:10 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 7 May 2010 23:42:10 -0000 Received: (qmail 10117 invoked by uid 500); 7 May 2010 23:42:10 -0000 Delivered-To: apmail-lucene-lucene-net-dev-archive@lucene.apache.org Received: (qmail 10085 invoked by uid 500); 7 May 2010 23:42:10 -0000 Mailing-List: contact lucene-net-dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucene.apache.org Delivered-To: mailing list lucene-net-dev@lucene.apache.org Received: (qmail 10075 invoked by uid 99); 7 May 2010 23:42:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 May 2010 23:42:10 +0000 X-ASF-Spam-Status: No, hits=-1403.6 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 May 2010 23:42:09 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o47NfmFR001974 for ; Fri, 7 May 2010 23:41:49 GMT Message-ID: <28995972.42231273275708689.JavaMail.jira@thor> Date: Fri, 7 May 2010 19:41:48 -0400 (EDT) From: "Digy (JIRA)" To: lucene-net-dev@lucene.apache.org Subject: [jira] Updated: (LUCENENET-358) CloseableThreadLocal memory leak in LocalDataStoreSlot (with workaround) In-Reply-To: <6356438.32461272370652508.JavaMail.jira@thor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LUCENENET-358?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Digy updated LUCENENET-358: --------------------------- Attachment: CloseableThreadLocal.patch Hi Robert, Very nice patch, thanks. But I have problems with your .diff files (maybe since I use TortoiseSVN). So, I will attach a ".patch" file for those who use TortoiseSVN. DIGY > CloseableThreadLocal memory leak in LocalDataStoreSlot (with workaround) > ------------------------------------------------------------------------- > > Key: LUCENENET-358 > URL: https://issues.apache.org/jira/browse/LUCENENET-358 > Project: Lucene.Net > Issue Type: Bug > Environment: Microsoft WIndows Server 2008 Enterprise x64. SP2. > .NET Framework 4.0 > Reporter: Rezgar Cadro > Priority: Critical > Attachments: CloseableThreadLocal MemoryLeak.patch, CloseableThreadLocal.diff, CloseableThreadLocal.patch > > > Recently we have been suffering from a severe memory leak when executing intense open/close operations on IndexSearcher and IndexModifier. > Memory profiling showed that memory is being held by LocalDataStore[] objects. > After some digging, the root of the problem has been found in CloseableThreadLocal class: > private System.LocalDataStoreSlot t = System.Threading.Thread.AllocateDataSlot(); > What we see is that every instantiated object of CloseableThreadLocal causes new data slot allocation performed for every thread. > Thread.AllocateDataSlot() does not simply allocate a new slot, replacing an old one, but enlarging an existing buffer in-thread, appending data to the end of internal LocalDataStore[] collection, which causes a severe memory leak . > As long as "t" variable is instantiated on every object creation, and (in current class implementation) every object is used by a single thread, replacing "private System.LocalDataStoreSlot t = System.Threading.Thread.AllocateDataSlot();" with simple "private object dataSlot;" and removing "hardRefs" Dictionary solves the problem and prevents memory leak. > We have tried to implement the expected behavior by using [ThreadStatic] attribute instead of LocalDataStoreSlot, but the attempt failed because of unexpected exceptions being thrown. > Patch can be found at Lucene.Net repository under -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.