Forum Stats

  • 3,768,728 Users
  • 2,252,841 Discussions
  • 7,874,698 Comments

Discussions

Memory leak after multiple open-close Environment

525672
525672 Member Posts: 2
edited Aug 14, 2006 4:00PM in Berkeley DB Java Edition
Hello, dear developers of JE

It seems to me that I face with insuperable obstacle.
I run JUnit3.8 tests on WindowsXP, 512Mb, JDK1.5. Before execute every test method in setup() I open Environment, create 3-5 Databases. Then put 3-10 small objects, read them. After test in tearDown() I close and remove all Databases, close Environment and remove its files from disk, collect garbage.

During running few test cases that consist of not more then 100 test methods OutOfMemoryError happens. Increasing of cache memory increases the number of executed test cases before crash. Setting je.log.memOnly to true accelerate raising the exception.
Separate test methods execution is successful.

Thanks, Alex

Comments

  • Charles Lamb
    Charles Lamb Member Posts: 836
    Hello Alex,

    We used to see the same problem with our own test suites. The problem is that if you don't close the environment after each test, it may be keeping pointers to enough referenced objects in the cache to overflow memory.

    You can try a couple of things:

    (1) Close the environment at the end of each test (and reopen it at the beginning of each test after that).

    (2) Set your cache size lower. The default is that it's taking 60% of your heap (-Xmx).
    I hope this is useful.

    Charles Lamb
  • Charles Lamb
    Charles Lamb Member Posts: 836
    Hi Again Alex,

    A colleague has pointed out that you may want to take a look at some of our unit tests for general form to model yours against. For instance, take a look at

    <je-home>/test/com/sleepycat/persist/test/BindingTest.java

    for an example of how we do setup and tearDown relative to the environment.

    Charles Lamb
  • 525672
    525672 Member Posts: 2
    After set of experiments I came to conclusion that your advice
    - to decrease the cache size and
    - to close all Environments with jdb files removing both in setUp and tearDown methods
    help me to stabilize unit test execution.

    Thank you, Charles
    --
    Regards, Alex
This discussion has been closed.