You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Igor Sereda (JIRA)" <ji...@apache.org> on 2012/10/27 17:37:11 UTC

[jira] [Created] (DERBY-5963) Memory leak when shutting down Derby system

Igor Sereda created DERBY-5963:
----------------------------------

             Summary: Memory leak when shutting down Derby system
                 Key: DERBY-5963
                 URL: https://issues.apache.org/jira/browse/DERBY-5963
             Project: Derby
          Issue Type: Bug
          Components: Store
    Affects Versions: 10.9.1.0, 10.5.3.0
         Environment: Embedded Derby
Windows 7
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

            Reporter: Igor Sereda


I am using an embedded Derby on a server within OSGi environment, as a private library in my bundle. When the bundle is deactivated, I stop Derby database (with jdbc:derby:;shutdown=true;deregister=true URL)

But although otherwise the database is released, an instance of ContextManager stays in memory due to a leaked reference in a ThreadLocal variable (from ContextService, I presume). The instance of ContextManager is a big deal, because it also holds the whole page cache in memory (40MB), and also, via class loader, holds whole my OSGi bundle too.

Please let me know if you need any information on reproducing this problem.

Thanks!
Igor

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (DERBY-5963) Memory leak when shutting down Derby system

Posted by "Igor Sereda (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13485455#comment-13485455 ] 

Igor Sereda commented on DERBY-5963:
------------------------------------

Attached a screenshot of Yourkit profiler showing the problem
                
> Memory leak when shutting down Derby system
> -------------------------------------------
>
>                 Key: DERBY-5963
>                 URL: https://issues.apache.org/jira/browse/DERBY-5963
>             Project: Derby
>          Issue Type: Bug
>          Components: Store
>    Affects Versions: 10.5.3.0, 10.9.1.0
>         Environment: Embedded Derby
> Windows 7
> java version "1.6.0_31"
> Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
> Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
>            Reporter: Igor Sereda
>         Attachments: yourkit.png
>
>
> I am using an embedded Derby on a server within OSGi environment, as a private library in my bundle. When the bundle is deactivated, I stop Derby database (with jdbc:derby:;shutdown=true;deregister=true URL)
> But although otherwise the database is released, an instance of ContextManager stays in memory due to a leaked reference in a ThreadLocal variable (from ContextService, I presume). The instance of ContextManager is a big deal, because it also holds the whole page cache in memory (40MB), and also, via class loader, holds whole my OSGi bundle too.
> Please let me know if you need any information on reproducing this problem.
> Thanks!
> Igor

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (DERBY-5963) Memory leak when shutting down Derby system

Posted by "Igor Sereda (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13485459#comment-13485459 ] 

Igor Sereda commented on DERBY-5963:
------------------------------------

Also, I found this in the comments in ServiceContext:

=====
There are two cases we are trying to optimise.
- Typical JDBC client program where there a Connection is always executed using a single thread. In this case this variable will contain the Connection's context manager
- Typical application server pooled connection where a single thread may use a connection from a pool for the lifetime of the request. In this case this variable will contain a *WeakReference*.
=====

I have the second case, and I don't see any WeakReferences being used.
                
> Memory leak when shutting down Derby system
> -------------------------------------------
>
>                 Key: DERBY-5963
>                 URL: https://issues.apache.org/jira/browse/DERBY-5963
>             Project: Derby
>          Issue Type: Bug
>          Components: Store
>    Affects Versions: 10.5.3.0, 10.9.1.0
>         Environment: Embedded Derby
> Windows 7
> java version "1.6.0_31"
> Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
> Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
>            Reporter: Igor Sereda
>         Attachments: yourkit.png
>
>
> I am using an embedded Derby on a server within OSGi environment, as a private library in my bundle. When the bundle is deactivated, I stop Derby database (with jdbc:derby:;shutdown=true;deregister=true URL)
> But although otherwise the database is released, an instance of ContextManager stays in memory due to a leaked reference in a ThreadLocal variable (from ContextService, I presume). The instance of ContextManager is a big deal, because it also holds the whole page cache in memory (40MB), and also, via class loader, holds whole my OSGi bundle too.
> Please let me know if you need any information on reproducing this problem.
> Thanks!
> Igor

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (DERBY-5963) Memory leak when shutting down Derby system

Posted by "Igor Sereda (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5963?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Sereda updated DERBY-5963:
-------------------------------

    Attachment: TestDerbyLeak.java
    
> Memory leak when shutting down Derby system
> -------------------------------------------
>
>                 Key: DERBY-5963
>                 URL: https://issues.apache.org/jira/browse/DERBY-5963
>             Project: Derby
>          Issue Type: Bug
>          Components: Store
>    Affects Versions: 10.5.3.0, 10.9.1.0
>         Environment: Embedded Derby
> Windows 7
> java version "1.6.0_31"
> Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
> Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
>            Reporter: Igor Sereda
>         Attachments: TestDerbyLeak.java, yourkit.png
>
>
> I am using an embedded Derby on a server within OSGi environment, as a private library in my bundle. When the bundle is deactivated, I stop Derby database (with jdbc:derby:;shutdown=true;deregister=true URL)
> But although otherwise the database is released, an instance of ContextManager stays in memory due to a leaked reference in a ThreadLocal variable (from ContextService, I presume). The instance of ContextManager is a big deal, because it also holds the whole page cache in memory (40MB), and also, via class loader, holds whole my OSGi bundle too.
> Please let me know if you need any information on reproducing this problem.
> Thanks!
> Igor

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (DERBY-5963) Memory leak when shutting down Derby system

Posted by "Igor Sereda (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13485475#comment-13485475 ] 

Igor Sereda commented on DERBY-5963:
------------------------------------

More investigation showed that this problem happens if a connection is ever shared between more than one thread.

Attached please find a demo code. I couldn't unit-test it because some internal stuff is used. Use a profiler to see that the database is held in memory.

As a workaround, I will have to use reflection to clean up all active threads.
                
> Memory leak when shutting down Derby system
> -------------------------------------------
>
>                 Key: DERBY-5963
>                 URL: https://issues.apache.org/jira/browse/DERBY-5963
>             Project: Derby
>          Issue Type: Bug
>          Components: Store
>    Affects Versions: 10.5.3.0, 10.9.1.0
>         Environment: Embedded Derby
> Windows 7
> java version "1.6.0_31"
> Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
> Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
>            Reporter: Igor Sereda
>         Attachments: TestDerbyLeak.java, yourkit.png
>
>
> I am using an embedded Derby on a server within OSGi environment, as a private library in my bundle. When the bundle is deactivated, I stop Derby database (with jdbc:derby:;shutdown=true;deregister=true URL)
> But although otherwise the database is released, an instance of ContextManager stays in memory due to a leaked reference in a ThreadLocal variable (from ContextService, I presume). The instance of ContextManager is a big deal, because it also holds the whole page cache in memory (40MB), and also, via class loader, holds whole my OSGi bundle too.
> Please let me know if you need any information on reproducing this problem.
> Thanks!
> Igor

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (DERBY-5963) Memory leak when shutting down Derby system

Posted by "Igor Sereda (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5963?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Sereda updated DERBY-5963:
-------------------------------

    Attachment: yourkit.png
    
> Memory leak when shutting down Derby system
> -------------------------------------------
>
>                 Key: DERBY-5963
>                 URL: https://issues.apache.org/jira/browse/DERBY-5963
>             Project: Derby
>          Issue Type: Bug
>          Components: Store
>    Affects Versions: 10.5.3.0, 10.9.1.0
>         Environment: Embedded Derby
> Windows 7
> java version "1.6.0_31"
> Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
> Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
>            Reporter: Igor Sereda
>         Attachments: yourkit.png
>
>
> I am using an embedded Derby on a server within OSGi environment, as a private library in my bundle. When the bundle is deactivated, I stop Derby database (with jdbc:derby:;shutdown=true;deregister=true URL)
> But although otherwise the database is released, an instance of ContextManager stays in memory due to a leaked reference in a ThreadLocal variable (from ContextService, I presume). The instance of ContextManager is a big deal, because it also holds the whole page cache in memory (40MB), and also, via class loader, holds whole my OSGi bundle too.
> Please let me know if you need any information on reproducing this problem.
> Thanks!
> Igor

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira