[bdb bug]repeatly open and close db may cause memory leak

my test code is very simple :
char *filename = "xxx.db";
char *dbname = "xxx";
for( ; ;)
DB *dbp;
DB_TXN *txnp;
db_create(&dbp,dbenvp, 0);
dbenvp->txn_begin(dbenvp, NULL, &txnp, 0);
ret = dbp->open(dbp, txnp, filename, dbname, DB_BTREE, DB_CREATE, 0);
if(ret != 0)
printf("failed to open db:%s\n",db_strerror(ret));
return 0;
txnp->commit(txnp, 0);
dbp->close(dbp, DB_NOSYNC);
I try to run my test program for a long time opening and closing db repeatly, then use the PS command and find the RSS is increasing slowly:
ps -va
PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
1986 pts/0 S 0:00 466 588 4999 980 0.3 -bash
2615 pts/0 R 0:01 588 2 5141 2500 0.9 ./test
after a few minutes:
ps -va
PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
1986 pts/0 S 0:00 473 588 4999 976 0.3 -bash
2615 pts/0 R 30:02 689 2 156561 117892 46.2 ./test
I had read bdb's source code before, so i tried to debug it for about a week and found something like a bug:
If open a db with both filename and dbname, bdb will open a db handle for master db and a db handle for subdb,
both of the two handle will get an fileid by a internal api called __dbreg_get_id, however, just the subdb's id will be
return to bdb's log region by calling __dbreg_pop_id. It leads to a id leak if I tried to open and close the db
repeatly, as a result, __dbreg_add_dbentry will call realloc repeatly to enlarge the dbentry area, this seens to be
the reason for RSS increasing.
Is it not a BUG?
sorry for my pool english :)
Edited by: user9222236 on 2010-2-25 下午10:38

I have tested my program using Oracle Berkeley DB release 4.8.26 and 4.7.25 in redhat 9.0 (Kernel 2.4.20-8smp on an i686) and AIX Version 5.
The problem is easy to be reproduced by calling the open method of db handle with both filename and dbname being specified and calling the close method.
My program is very simple:
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include "db.h"
int main(int argc, char * argv[])
int ret, count;
DB_ENV *dbenvp;
char * filename = "test.dbf";
char * dbname = "test";
db_env_create(&dbenvp, 0);
dbenvp->open(dbenvp, "/home/bdb/code/test/env",DB_CREATE|DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_INIT_MPOOL, 0);
for(count = 0 ; count < 10000000 ; count++)
DB *dbp;
DB_TXN *txnp;
db_create(&dbp,dbenvp, 0);
dbenvp->txn_begin(dbenvp, NULL, &txnp, 0);
ret = dbp->open(dbp, txnp, filename, dbname, DB_BTREE, DB_CREATE, 0);
if(ret != 0)
printf("failed to open db:%s\n",db_strerror(ret));
return 0;
txnp->commit(txnp, 0);
dbp->close(dbp, DB_NOSYNC);
dbenvp->close(dbenvp, 0);
return 0;
DB_CONFIG is like below:
set_cachesize 0 20000 0
set_flags db_auto_commit
set_flags db_txn_nosync
set_flags db_log_inmemory
set_lk_detect db_lock_minlocks
Edited by: user9222236 on 2010-2-28 下午5:42
Edited by: user9222236 on 2010-2-28 下午5:45

Similar Messages

  • Finder repeatedly opens and closes in my PowerBook G4

    I have been wrestling with this problem for some time. Finder repeatedly opens and closes in my PowerBook G4. When I log in to my Administrator Account, the Finder will repeatedly open and close with a rainbow spinner till the whole system freezes. I have reinstalled the OS and the problem returned. Now, I need to get my files on that account backed up and start over again. The trouble is that I can't access the files because the Finder isn't accessible. I've created a 2nd account, and am in the process of trying to copy the files I need to the new profile, but so far those files are barred. My main concern is why is this happening, and will it happen again if I reinstall? What's the best way to reinstall and start over?

    If the second account is an admin one and since the issue is specific to your original user account, you can proceed in two ways. One is to log into your new account, make a list of the preference files (plists) located in /username/Library/Preferences/, including any in the ByHost subfolder, log back into the original account, move everything on that other account's list from the original account's Preferences folder into a newly created folder on the Desktop, log out and back in, and see if the problem goes away. If so, you can copy the ones in the Desktop folder (one at time) back into /Preferences/, restart, and see if the problem returns. If so, you've identified the corrupt/conflicting one. Continue with all of them until isolating the bad ones. That'll save you the trouble of resetting preferences.
    The second way is much more detailed and I'll not burden you with the steps unless the above doesn't fix the issue.

  • Trackpad is presenting a bug to open and close windows, mission control, and to move/roll the application (App) up and down.

    Totally out of the blue, my trackpad is presenting a "bug". Every time that I try to open and close my mission control, or in the moments that I move / roll up and downs the Applications Screen, my Mac freezes for less than a second.
    It never suffered any damage (NEVER!)! I am feeling very frustrated because I have no idea about what could cause such problem.
    My MacBook Air is running OS X 10.9.5.
    Any help will be very welcome!

    Well, it all really depends on the custom program and how it was written. Does it have an ActiveX interface? If it does, than that's the easiest way to go. If you put an automation refnum on the fron panel, you can right click and it and choose Select ActiveX Class>Browse. The browser will list all of the ActiveX type libraries that are registered on your system. If you can find one that refers to your custom program, then you should be able to use it's methods and properties to control. If it does not have an ActiveX interface, then things get much more difficult.

  • Since installing LTR 5.4, which I've now upgraded to 5.6, I've encountered repeated slowness and malfunctions in operations, especially when using the Compare View function and the Tab key to open and close the right and left side panels.  Such problems n

    Since installing LTR 5.4, which I've now upgraded to 5.6, I've encountered repeated slowness and malfunctions in operations, especially when using the Compare View function and the Tab key to open and close the right and left side panels.  Such problems never arose during two years of using LTR-4 and nothing else has changed on my computer.  I have a pretty simple system with only a few plug-ins, which are usually not in operation.  I have 12GB of RAM in my Windows 7 PC.  I could illustrate these problems with screen shots if you would tell me how to submit screen shots.  Otherwise I will try to describe the problems in words.
    The problem is clearly cumulative, growing worse as usage time passes.  Compare View feature gradually slows down and eventually seems to choke as my work session proceeds. If I Exit LTR and re-enter and start all over, things will work normally for maybe 30 minutes, but then the Compare View feature begins to become very slow to respond.   In a recent example with my screen full of thumbnails in Library mode I highlighted two images to compare. LTR started to open the Compare View screen by first having the top row of thumbnails disappear to be replaced by the "SELECT" and "CANDIDATE" words in their spaces  (but no images), but Compare View never succeeded in gaining control of the screen. After some seconds the top row of thumbnails reasserted its position and the Compare View windows disappeared. But LTR kept trying to bring them back. Again the top row of thumbnails would go away, Select and candidate would reappear, try again, and give up. This went on for at least 2-3 minutes before I tried to choose File and Exit, but even that did not initially want to respond. It doesn't like to accept other commands when it's trying to open Compare View. Finally it allowed me to exit.
    To experiment I created a new catalog of 1100 images.  After 30-40 minutes, the Compare View function began to operate very slowly. With left and right side panels visible and two thumbnails highlighted, hitting Compare View can take half a minute before the two mid-size  images open in their respective SELECT and CANDIDATE windows. When the side panels are open and two images are in the Select/Candidate spaces, hitting the Tab button to close the side panels produces a very delayed response--25-30 seconds to close them, a few more seconds to enlarge the two images to full size. To reverse the process (i.e., to recall the two side panels), hitting Tab would make the two sides of the screen go black for up to a minute, with no words visible. Eventually the info fields in the panels would open up.
    I also created a new user account and imported a folder of 160 images. After half an hour Compare View began mis-placing data.  (I have a screen shot to show this.)  CANDIDATE appears on the left side of SELECT, whereas it should be on the right. The accompanying camera exposure data appears almost entirely to the left of the mid-screen dividing line. Although the Candidate and Select headings were transposed, the image exposure data was not, but the data for the image on the right was almost entirely to the left of the line dividing the screen in two.
    Gurus in The Lightroom Forum have examined Task Manager data showing Processes running and Performance indicators and they see nothing wrong.  I could also send screen shots of this data.
    At this point, the only way I can process my images is to work 30-40 minutes and then shut down everything, exit, and re-start LTR.  This is not normal.  I hope you can find the cause, and then the solution.  If you would like to see my screen shots, tell me how to submit them.
    Ollie
    [email protected]

    Since installing LTR 5.4, which I've now upgraded to 5.6, I've encountered repeated slowness and malfunctions in operations, especially when using the Compare View function and the Tab key to open and close the right and left side panels.  Such problems never arose during two years of using LTR-4 and nothing else has changed on my computer.  I have a pretty simple system with only a few plug-ins, which are usually not in operation.  I have 12GB of RAM in my Windows 7 PC.  I could illustrate these problems with screen shots if you would tell me how to submit screen shots.  Otherwise I will try to describe the problems in words.
    The problem is clearly cumulative, growing worse as usage time passes.  Compare View feature gradually slows down and eventually seems to choke as my work session proceeds. If I Exit LTR and re-enter and start all over, things will work normally for maybe 30 minutes, but then the Compare View feature begins to become very slow to respond.   In a recent example with my screen full of thumbnails in Library mode I highlighted two images to compare. LTR started to open the Compare View screen by first having the top row of thumbnails disappear to be replaced by the "SELECT" and "CANDIDATE" words in their spaces  (but no images), but Compare View never succeeded in gaining control of the screen. After some seconds the top row of thumbnails reasserted its position and the Compare View windows disappeared. But LTR kept trying to bring them back. Again the top row of thumbnails would go away, Select and candidate would reappear, try again, and give up. This went on for at least 2-3 minutes before I tried to choose File and Exit, but even that did not initially want to respond. It doesn't like to accept other commands when it's trying to open Compare View. Finally it allowed me to exit.
    To experiment I created a new catalog of 1100 images.  After 30-40 minutes, the Compare View function began to operate very slowly. With left and right side panels visible and two thumbnails highlighted, hitting Compare View can take half a minute before the two mid-size  images open in their respective SELECT and CANDIDATE windows. When the side panels are open and two images are in the Select/Candidate spaces, hitting the Tab button to close the side panels produces a very delayed response--25-30 seconds to close them, a few more seconds to enlarge the two images to full size. To reverse the process (i.e., to recall the two side panels), hitting Tab would make the two sides of the screen go black for up to a minute, with no words visible. Eventually the info fields in the panels would open up.
    I also created a new user account and imported a folder of 160 images. After half an hour Compare View began mis-placing data.  (I have a screen shot to show this.)  CANDIDATE appears on the left side of SELECT, whereas it should be on the right. The accompanying camera exposure data appears almost entirely to the left of the mid-screen dividing line. Although the Candidate and Select headings were transposed, the image exposure data was not, but the data for the image on the right was almost entirely to the left of the line dividing the screen in two.
    Gurus in The Lightroom Forum have examined Task Manager data showing Processes running and Performance indicators and they see nothing wrong.  I could also send screen shots of this data.
    At this point, the only way I can process my images is to work 30-40 minutes and then shut down everything, exit, and re-start LTR.  This is not normal.  I hope you can find the cause, and then the solution.  If you would like to see my screen shots, tell me how to submit them.
    Ollie
    [email protected]

  • IChat opens and closes repeatedly

    I've seen this come up in discussions a few times but without answers.
    iChat opens and closes repeated then tells me I've logged in too many times and to try again later. BUT... this only happens on one particular Airport connection. Everywhere else is fine. Is it the wireless router that is the problem... some compatibility issue? Is that the issue for the other people getting this problem too, perhaps?
    Any ideas how to fix this?

    Hi,
    From that (9C7010) I can see that you have done the Time Machine and Airport Update.
    I presume this updates the specs for the Airport Card as well as adjusting the Airport Devices themselves to Apple's version of the latest 802.11n draft spec.
    I would have then said that it was effecting the connection presumably as this is now out of step with the firmware on the Netgear, but you say other Internet features work.
    First I would delete the com.apple.iChat.AIM.plist from Users/(your account)/Library/Preferences
    Then I would see if this Netgear is set to Respond to Internet Pings and has the Block Port Scan and DOS (or SPI) turned Off.
    As test I would see if the N spec can be turned off in the Netgear and use the G only.
    4:39 PM Sunday; April 6, 2008

  • Ichat opens and closes repeatedly then shows an error

    When I go to log into Ichat, it opens and closes over and over again until finally an error comes up saying that I tried to log in too many times, and to try and log in again later.
    However, after a few minutes, it still does not let me log in.. Please help !

    I looked further into the discussions and found this thread. I tried it and it worked. It might work for you.
    http://discussions.apple.com/thread.jspa?threadID=1825154&tstart=60
    Good luck!

  • Open and Close Front Panel of SubVI

    Hi all,
    Running LabVIEW 2011 on Windows 7 x64.  I am trying to get a subVI front panel to open from my main FP with the press of a button and then close with a button press in the subVI.  Here is the piece from my main FP that calls the VI and opens the FP 
    Plots is defined in another loop and all of the loops are in a flat sequence.  I did it this way because I want it to start with the first press and not stop my main loop from running.  I have moved the item in the left loop around a lot so I'm not sure if I can run that in the same loop as the event or not.  Either way opening the VI seems to work fine.
    The problem shows up when trying to close the subVI for the SECOND time.  The code is here:
    As I said, the first time I open and close the VI everything works as I expect it should.  I am then able to open it again but now the "blank button" doesn't function and I can't close the window or even open the block diagram to probe anything.  I have been trying to figure this out for awhile, any insite would be greatly appreciated!
    Thanks
    Solved!
    Go to Solution.

    Its good that you found the bug.
    This code may serve as a way for you to compare notes.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Pages 09 document; open and close many times; right way with Lion?

    I have a 106 page document that increases in size on a daily basis. With OS 10.7, iWork/Pages 09 on my new, iMac, it's common that I lose as much as two sentences after the document is closed and re opened. After 10.7 was installed the document was closed using Command - S, and subsequently closed by pulling down File and selecting Close. - Not the way to close; the red button was so easy with 10.6. IS UNINSTALLING LION THE BEST SOLUTION?
    And yes, I've read the sorry jibberish in the Pages 09 manual - which doesn't say how to open and close repeatedly a document with Pages 09.
    So, with the Lion - the worst ever of spending $30, is it necessary to do a Command S every time you close? And what exactly is necessary each time you close a document using Pages 09 and Lion? - And about Auto Save; well, what about Auto Save? - The Lion means well for something other than common, understandable, text production.  -- How about a separate application of Appleworks for text producers like me?

    The red button is always available under 10.7 (or 10.7.1)
    Under 10.7, press cmd + S once when you create the document.
    After that, the system automatically save your changes.
    No need for cmd + S.
    To close the document we may use :
    the red button
    cmd + W
    File > Close
    as it was with older systems.
    monte45 wrote:
    And yes, I've read the sorry jibberish in the Pages 09 manual - which doesn't say how to open and close repeatedly a document with Pages 09.
    The User Guide is perfectly clear and precise :
    Yvan KOENIG (VALLAURIS, France) jeudi 22 septembre 2011 19:21:52
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • Apps in iPad 1 open and close quickly

    Hello,
    My mother has an iPad 1 (she has her own itunes account) but had never synced and updated her iPad with a computer (pc or mac).
    Today I had to use it and connected to my iTunes on the pc but only to update her iOS on the iPad wich was 3.x. After the whole update process (wich went normal and smooth) almost every app that I woud open, closed imeadtly. I say ALMOST because, a few from the default apps (like Mail, Photos, Safari, System, etc) opens normaly. Though iBooks doesnt and all 3rd party apps also doesnt open normaly.
    I've tryed to reboot it one more time thinking it was some kind of strange bug or something but didn't work. The apps continue to open and close almost instantly.
    I'd like to know if anyone had a similar problem and how they solved it or if my only resource is to roll back to the iPad backup made in my pc.
    Thanks in advance.
    Luis Felipe

    Try double-tapping the home button, then holding the app icon until the minus sign appears. Touch the minus sign to kill all the apps. Then restart the iPad with the home/power buttons (hold for ten seconds) until the apple appears.

  • What is the better way to open and close connection in bean

    Hello, may i ask about the best way to open and close the connection?
    At the first, the connection code is store in Conn class bean. The JSP page will call a method in Process bean to process the query and update of database. the Process bean is using th Conn to connect to database.
    In my process bean, it have a method for each type of sql like select, insert, update, and delete for each tables. Each method will call the Conn to open and close the connection. The jsp page can simply call a method retrieve or update records.
    However, when calling the processUpdate method, it is a method that update a group of tables base on the query result of another group of tables and calculation. If I calling the query method in the same bean file, it will open and close the connection many times (more than 1000 times). After open and close the connection several times, the connection to mySQL will be fail.
    Currently, i include 2 method in Process that is only calling the Conn to open the connection and close connection. When calling the openConnection method, it will also set the boolean connected in the class to true and call Conn to open connection. When calling the closeConnection method, it will also set the boolean connected in the class to false and call Conn to close connection.
    After that, i add some change to the query method which is when the connected is false, it will open the connection by calling the Conn and close the connection themself. If the connected is true, it will not call the Conn to open and close the connection because it already connected to the database.
    Now, i when i calling the query method in jsp, it can open the connection and close the connection individually. When i call the processUpdate in the jsp, this method will calling the openConnection before calling the query and calling closeConnection at the end. It not only faster the process(less open and close), it also no cause the connect to mySQL fail error again. However, it also make the coding in the bean file more longer and complex.
    Is there have any better solution?

    Use connection pooling. This will put the connection management in the hands of the webserver, not your code. Check out this post:
    http://forum.java.sun.com/thread.jspa?threadID=741788&messageID=4252932#4252932

  • Two intervals in Open and Close Posting Period (OB52)

    What is the purpose of the two intervals (period 1 and period 2) in Open and Close Posting Periods (transaction OB52)?

    Hi,
    Financial statements cannot be prepared on the last day of the accounting period... to find out the correct profit and to determine the correct financial positing... sometimes you may require to make some adjustment  to accounting records after the closing of the accounting year... like adjustments for expenses payable, income receivable, writting off bad debts ...etc. 
    For posting those transactions....period 2 is maintained ..which are also called as special periods... to make the postings in these periods ...special authorisation is required..... 
    Period 1 is for regular postings ...
    Radha

  • Project Takes FOREVER to Open and Close

    We have a large RoboHTML project that outputs to a WebHelp
    system. The version of RoboHelp is X 5, possibly a version after
    that, I think - but dated 2004. Two of us share this project, but
    we don't use Version Control. The size of the project is about 45
    MB, and includes several subfolders of topic HTMs. My coworker has
    the same issues, possibly a bit faster than what I have, but still
    excessive Open and Close Project times.
    It takes an extremely long time to open, like about 10
    minutes or more. When I select to Close Project, the CPU Usage
    shown in Task Manager is up to 100 % and stays there, so the
    closing process is maxed out and frozen, and obviously isn't happy.
    Even when I close other applications, the project can take over 30
    minutes to close - no error messages, just hourglassing. While I'm
    using the project, it doesn't max out. There have been times when,
    as much as I hated to do it, I had to do an End Task with Task
    Manager because the project wasn't closing (and I had to leave).
    Also, note that the CPD file of this project is over 4 MB. I
    just was reading about deleting the CPD file, so I plan on doing
    that.
    I'm not sure of any more details I can provide. While I'm
    working on the project, there are usually no freezes or response
    time problems. Just the extremely long Open Project time - and even
    longer Close Project time.
    I would so appreciate any solutions or ideas. Thanks!!!
    Susan

    Update - I deleted the CPD file, and it opened a lot faster!!
    It also closed in a reasonable amount of time - however, I did not
    work in the project for a while before I closed it. So we'll see
    what happens when I close it at the end of the day.
    So, the deletion of the CPD file may have solved the problem.
    However, if anyone wants to offer feedback on this possible
    solution, I would appreciate it.
    Thanks!
    Susan

  • IMessage beta loose all saved conversations when I open and close a window.

    iMessage beta looses all saved conversations when I open and close a window.
    Just reporting this bug... Could not find anyother place to do it.
    Jonathan

    I thought it was doing that also. But I found that if I start a new chat with someone I was messaging before, then the old messages re-appear in the messages window.

  • Logging open and close of documents?

    I'd like to have a record of when I open and close documents, so that I can support my diary notes of jobs I've been working on. So I need to have the filename recorded. I can find an app' to log application usage; is there one for file usage ?
    regards, alan

    Hi, alan.
    This search of VersionTracker reveals two apps that track document time. Of the two, T3, looks exactly like what you want, but it is expensive. Check out the developer's site
    Active Timer may be more to your liking: it can track time at the application window level and is free.
    You can investigate other solutions by searching MacUpdate or Version Tracker. The user-submitted reviews accompanying the listings can be helpful in sorting the wheat from the chaff. Try searches for time track and look at the various options each provides.
    Good luck!
    Dr. Smoke
    Author: Troubleshooting Mac® OS X

  • Is an Open and Close Stmt of some kind mandatory for BDC?

    If so what is the quickest way to code it? I am restricting a batch in an interface. In the same interface I unrestrict but it does not work. I am using BDC. I am thinking I may be missing some syntax for open close in my BDC.
         Thank-you

    With out open and close Group function it is not possible to create the sessioon and not possible to use the BDC session method. only when you open the session then only you should insert and close the Group.
    CALL FUNCTION 'BDC_OPEN_GROUP'.
    if Open = 'X'.
    CALL FUNCTION 'BDC_INSERT'.
    endif.
    if open = 'X'.
    CALL FUNCTIOn 'BDC_CLOSE_GROUP'.
    endif.

Maybe you are looking for