Does call to ptsname() cause memory leak?

Purify signalled that the call to ptsname() is a memory leak. ptsname() returns a char* and
apparently is doing this on the heap even though the man page says it is a static data area. My
question is whether we need to do a free() on the return from ptsname()?

I believe that there was a memory leak problem with DataSocket 3.0 which came with LabVIEW 5.1. Try upgrading DataSocket to 4.0.
http://digital.ni.com/softlib.nsf/web%2Fall%20software?OpenView&Start=1&Count=500&Expand=6#6
If that does not work, the problem may not have been resolved until LabVIEW 6. Also, if you happened to be using the French version of LabVIEW, contact tech support, there was a specific problem there which does have a work around.

Similar Messages

  • Applet calling javascript function causing memory leak

    Hi,
    I'm troubleshooting one memory leak issue in my application and to do that I created one simple Java applet and HTML + javascript function to locate the problem.
    Basically it's an applet calling a javascript function using a timer. The javascript function simply does nothing.
    I tested in IE 8.0 and JRE 1.6.0_23-b05 and memory of IE keeps increasing.
    I saw this bug http://bugs.sun.com/view_bug.do?bug_id=6857340 which seems related with my issue, but if I understand correctly from the page, the issue should have been fixed.
    I posted this message to find out if others also find same issue and if there's a solution for this. If I comment out window.call("dummy", null); , memory will not climb up.
    Java code
    +public class Main extends Applet implements Runnable  {+
    public Applet currentApplet= this ;
    +     public JSObject window = null;+
    +public void run(){+
    +          System.out.println("run..");+
    +     }+
    +public void start(){+
    window = JSObject.getWindow(this);
    int delay = 300; //milliseconds
    +ActionListener taskPerformer = new ActionListener() {+
    +public void actionPerformed(ActionEvent evt) {+
    window.call("dummy", null);
    +}+
    +};+
    new Timer(delay, taskPerformer).start();
    +     }+
    +public static void main(String[] args) {+
    +          System.out.println("start...");+
    +          Main main = new Main();+
    +     main.start();+
    +     }+
    +}+
    Javascript source code
    +<html>+
    +<head>+
    +<script>+
    +function dummy() {+
    +     +
    +}+
    +</script>+
    +</head>+
    +<body>+
    +<applet .... >+
    +...+
    +</html>+

    Try this url:
    http://www.inquiry.com/techtips/java_pro/10MinuteSolutions/callingJavaScript.asp
    It also provides some examples.

  • Calling SetLocalTime in C# causes Memory Leak (WEC7)

    Hello,
    I use SetLocalTime() in C#. Everything works well if I start explorer.exe and my application. But if I don't start explorer.exe at system start. SetLocalTime() causes memory leak in my application. I call the function frequently every hour.
    public static bool SetzeLokalZeit(SYSTEMDATETIME lpSystemTime)
    #if DEADLOCKDETECT
    using (DdMonitor.Lock(MyTimeLock, "MyTimeLock#1"))
    #else
    lock (MyTimeLock)
    #endif
    bool ret = false; // no Success
    try
    GLB.LogFile.MyWrite("SetLocalTime");
    SYSTEMDATETIME loc = new SYSTEMDATETIME();
    loc.wYear = lpSystemTime.wYear;
    loc.wMonth = lpSystemTime.wMonth;
    loc.wDayOfWeek = lpSystemTime.wDayOfWeek;
    loc.wDay = lpSystemTime.wDay;
    loc.wHour = lpSystemTime.wHour;
    loc.wMinute = lpSystemTime.wMinute;
    loc.wSecond = lpSystemTime.wSecond;
    loc.wMilliseconds = lpSystemTime.wMilliseconds;
    ret = SetLocalTime(ref loc);
    if (!ret) // no Success
    int err = Marshal.GetLastWin32Error();
    if (err > 0)
    GLB.LogFile.MyWrite("ERROR CODE:" + err.ToString());
    else ret = true;
    catch (Exception ex)
    GLB.LogFile.MyWrite("000023 Exception" + ex.Message);
    finally
    GLB.LogFile.MyWrite("SetLocalTime Ende");
    return ret;
    Has someone an idea what's the problem?
    Best regards,
    Andreas

    Hello,
    Here the answers to the questions:
    1. Does the SetLocalTime function succeed?
    Calling SetLocalTime doesn't cause an exception an the local time is set correctly.
    2. Do you still get the memory leak if you remove all other calls?
    Yes. I have removed any other code, but I also get the memory leak.
    3. Does the memory leak also occur when you do this from native code?
    I have not tried it yet. But I will still make it...
    [DllImport("coredll.dll")]
    private static extern void GetLocalTime(ref SYSTEMDATETIME lpSystemTime);
    [DllImport("coredll.dll", SetLastError = true)]
    private static extern bool SetLocalTime(ref SYSTEMDATETIME lpSystemTime);
    [StructLayout(LayoutKind.Sequential)]
    public struct SYSTEMDATETIME
    public ushort wYear;
    public ushort wMonth;
    public ushort wDayOfWeek;
    public ushort wDay;
    public ushort wHour;
    public ushort wMinute;
    public ushort wSecond;
    public ushort wMilliseconds;
    public static bool Pub_SetLocalTime(SYSTEMDATETIME lpSystemTime)
    lock (MyTimeLock)
    bool ret = false; // no Success
    try
    loc_set.wYear = lpSystemTime.wYear;
    loc_set.wMonth = lpSystemTime.wMonth;
    loc_set.wDayOfWeek = lpSystemTime.wDayOfWeek;
    loc_set.wDay = lpSystemTime.wDay;
    loc_set.wHour = lpSystemTime.wHour;
    loc_set.wMinute = lpSystemTime.wMinute;
    loc_set.wSecond = lpSystemTime.wSecond;
    loc_set.wMilliseconds = lpSystemTime.wMilliseconds;
    ret = SetLocalTime(ref loc_set);
    if (!ret) // no Success
    int err = Marshal.GetLastWin32Error();
    if (err > 0)
    MessageBox.Show("Win32 Error:", err.ToString());
    else ret = true;
    catch (Exception ex)
    MessageBox.Show("SetLocalTime,Exception:", ex.ToString());
    finally
    return ret;
    Best regards,
    Andreas

  • JSF: partial page rendering is causing memory leak leading to outofmemory

    JDeveloper 10.1.3.2.0
    JDK: 1.6.0_06
    Operating System: Windows XP.
    I test my application for memory leaks. For that purpose, I use jconsole to monitor java heap space. I have an edit page that has two dependent list components. One displays all countries and the other displays cities of the selected country.
    I noticed java heap space keeps growing as I change country from country list.
    I run garbage collection and memory usage does not go down. If I keep changing the province for 5 minutes, then I hit a java heap space outofmemory exception.
    To narrow down the problem, I removed the second city component and the problem still exists.
    To narrow it down further, I removed autosubmit attribute from the country component and then memory usage stopped increasing as I change country.
    country/city partial page rendering is just an example. I am able to reproduce the same problem on every page where i use partial page rendering. My conclusion is PPR is causing memory leak or at least the autosubmit attribute.
    This is really bad. Anyone out there experienced same issue. Any help/advice is highly appreciated !!
    Thanks
    <af:panelLabelAndMessage
    inlineStyle="font-weight:bold;"
    label="Country:"
    tip=" "
    showRequired="true"
    for="CountryId">
    <af:selectOneChoice id="CountryId"
                   valuePassThru="true"
                   value="#{bindings.CountryId.inputValue}"
                   autoSubmit="true"
                   inlineStyle="width:221px"
                   simple="true">
         <af:forEach var="item"
              items="#{bindings.CountriesListIterator.allRowsInRange}">
         <af:selectItem value="#{item.countryId}"
                   label="#{item.countryName}"/>
         </af:forEach>
    </af:selectOneChoice>
    </af:panelLabelAndMessage>
    <af:panelLabelAndMessage
    inlineStyle="font-weight:bold;"
    label="City:"
    tip=" "
    showRequired="true"
    for="CityId">
    <af:selectOneChoice id="CityId"
                   valuePassThru="true"
                   value="#{bindings.CityId.inputValue}"
                   partialTriggers="CountryId"
                   autoSubmit="true"
                   inlineStyle="width:221px"
                   unselectedLabel="--Select City--"
                   simple="true">
         <f:selectItems value="#{backing_CountryCityBean.citiesSelectItems}"/>
    </af:selectOneChoice>
    </af:panelLabelAndMessage>

    Samsam,
    I haven't seen this problem myself, no.
    To clarify - are you seeing this behaviour when running your app in JDeveloper, or when running in an application server? If in JDeveloper, a copuple of suggestions:
    * (may not matter, but...) It's not supported to run JDev 10g with JDK 6
    * have you tried the [url http://www.oracle.com/technology/pub/articles/masterj2ee/j2ee_wk11.html]memory profiler
    Best,
    John

  • SetObjectArrayElement causes memory leak

    Hello There,
    I have got a little problem that I'm not able to solve for myself. Look at this piece of
    JNI code:
    double** result = calculator->getResult();
    jobjectArray table = env->NewObjectArray(height, env->FindClass("[D"), 0);
    for (int i = 0;i < height;i++) {
         jdoubleArray row = env->NewDoubleArray(width);
         env->SetDoubleArrayRegion(row, 0, width, (jdouble*)result);
         env->SetObjectArrayElement(table, i, row);
         env->DeleteLocalRef(row);
    This fragment causes a memory leak , but if I omit the env->SetObjectArrayElement(table, i, row);
    call, there is no memory leak. I don't really know what exactly causes this memory leak and how
    to fix it. Any help would be greatly appreciated ;-)
    Michael                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Ok I think the code snippet I posted was not complete...
    double** result = calculator->getResult();
    jobjectArray table = env->NewObjectArray(height, env->FindClass("[D"), 0);
    for (int i = 0;i < height;i++) {
         jdoubleArray row = env->NewDoubleArray(width);
         env->SetDoubleArrayRegion(row, 0, width, (jdouble*)result);
         env->SetObjectArrayElement(table, i, row);
         env->DeleteLocalRef(row);
    jobject rawData = env->NewObject(classreg["data/rawdata1d"], methodIDreg["data/rawdata1d/init"], width, height);
    env->SetObjectField(rawData, fieldIDreg["data/rawdata1d/data"], table);
    return rawData;
    The array I create is set as a member of a Java object which
    is then returned by the native method. As long as this object
    is in use by my program it's clear that the memory I allocated
    for the array never gets released. But when the Java object is
    no longer used by my program and the garbage collector releases
    the memory occupied by this object, shouldn't it release the memory
    occupied by the array I created in my native method too? Apparently
    this is not the case, do I have to release the Java array for myself?
    Michael
    Edited by: Michael_JavaAddict on Aug 25, 2010 3:03 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Can Java program cause memory leak?

    Can Java program cause memory leak or memory crash? I don't mean any memory overflow related exceptions. I mean something like core dump in UNIX or error reports in Windows XP.
    If it can really happen, in what circumstances? I raise such a question because our J2EE based system had really caused memory leak in Windows XP systems, but so far we still fail to troubleshoot the problem.

    Your code may leak memory. There are many, many, many reasons this could be. All of them represent bugs in your code.
    You should get a profiler to identify the problem spots of your code.
    You spoke of a memory crash as well. The VM may crash with some bug in the VM, or a bug in native code but that is not relevent to your problem. A memory leak is a problem in your code.

  • Why does this extra REG EVENTS cause memory leak?

    LabVIEW 8.6.1f1, Win XP/Vista
    My client reported a memory leak in a particular section of my code - my own tests confirmed it.
    Although I have found it and eliminated it, I still don't understand what's really happening.
    The RTEC RECEIVER CONTROLLER vi produces a cluster with various (maybe 30) event refnums in it.
    For this particular piece of code, I am only interested in 5 of those events.
    I was experimenting with registering the cluster as a whole (it works), and I inadvertently left the 2nd REGISTER EVENTS function in place.
    So there are TWO event registration refnums, but only one of them is being used.
    As the program proceeds, more and more memory is being consumed by LabVIEW (as reported by Windows Resource Monitor).  Leaving the program with this particular window running overnight would use up a gig or RAM.
    I verified that nothing else was consuming it - disabling the actual data handling did not fix the problem - eliminating this extra registration did fix it.
    So my question is - why?
    The registration only happens once, and then there are a million events or more in a 12-hour period.
    I can guess that the registration creates some sort of queue within LabVIEW for the events to reside in.  With no EVENT structure tied to that refnum to consume the events, that queue expands forever.
    Is that a reasonable guess, or is there something I am missing?
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

    CoastalMaineBird wrote:
    I can guess that the registration creates some sort of queue within LabVIEW for the events to reside in.  With no EVENT structure tied to that refnum to consume the events, that queue expands forever.
    Is that a reasonable guess, or is there something I am missing?
    Yes, it's a very reasonable guess and is most likely what's happening.
    You might say "LabVIEW could see I'm not actually doing anything with the reference and could therefore optimize the code by ignoring it (which is something LV does in some other cases)", but I'm assuming this is a corner case whoever wrote the original code did not think about, because this could be implemented only in a case where the node neither outputs a reference nor gets one as an input.
    Try to take over the world!

  • CVI dll to read XML file causes memory leak

    Hello,
    I am facing a memory leak issue when I execute a dll created using CVI to read a XML file.
    Each iteration of the step is taking around 200k of memory.
    Short description of the code:
    Basically I am using a function created in CVI to read from an XML file by tag which 2 attributes: command and the response;
    int GetCmdAndRsp(char XML_File[MAX_STR_SIZE], char tag[MAX_STR_SIZE], char Command[MAX_STR_SIZE], char Response[MAX_STR_SIZE], char ErrorDescription[MAX_STR_SIZE]) 
    inputs:  
    - XML_File_path;
    - tagToFind;
    ouputs:
    - Command;
    - Response;
    - Error;
    Example:
    XMLFile:
    <WriteParameter Command="0x9 %i %i %i %i %i" Response = "0x8 V %i %i %i %i"/>
    Execution:
    error = GetCmdAndRsp("c:\\temp\\ACS_Messages.xml" ,"WriteParameter", cmd, rsp, errStr) 
    output:
    error = 0
    cmd = "0x9 %i %i %i %i %i"
    rsp = "0x8 V %i %i %i %i"
    errStr = "Unkown Error"
    Everything is working correctly but I have this memory leak issue. Why am I having such memory consumption?? Is it a TestStand or CVI issue??
    Each iteration I am loading the file, reading the file and discarding the file.
    Attached you can find the CVI project, a TestStand sequence to test (ReadXML_test2.seq) and an example of a XML file I am using.
    Please help me here.
    Thaks in advance.
    Regards,
    Pedro Moreira
    Attachments:
    ReadXML_Prj.zip ‏1826 KB

    Pedro,
    When a TestStand step executes, its result will be stored by TestStand which will be later used for generating reports or logging data into database.
    You are looking at the memory (private bytes) when the sequence file has not finished execution. So, the memory you are looking at, includes the memory used by TestStand to store result of the step. The memory used for storing results will be de-allocated after finishing the sequence file execution.
    Hence, we dont know if there is actual memory leak or not. You should look at the memory, before and after executing sequence file instead of looking in between execution.
    Also, here are some pointers that will be helpful for checking memory leak in an application:
    1. TestStand is based on COM and uses BSTR in many function. BSTR caches the memory and because of the behavior, sometime you might get false notion of having memory leak. Hence, you need to use SetOaNoCache function OR set the OANOCACHE=1 environment variable to disable caching.
    2. Execute the sequence file atleast once before doing the actual memory leak test. The dry run will make sure all static variables are initialized before doing memory leak test.
    3. Make sure that the state of system or application is same when considering the Private bytes. Ex: Lets say ReportViewControl is not visible before you start executing sequence file. Then you note down the private bytes and then execute the sequence file. After finishing execution, make sure you close the ReportViewControl and then note down the private bytes once again to check if memory is leaked or not.
    4. If there exists memory leak as you specified, it is possible that the leak is either in TestStand, or in your code. Make sure that your code doesn't leak by creating a small standalone application (probably a console application) which calls your code.
    Detecting memory leaks in CVI is better explained in
    http://www.ni.com/white-paper/10785/en/
    http://www.ni.com/white-paper/7959/en/
    - Shashidhar

  • The Security ID is not valid causes memory leak in Ldap

    Hi, all:
    We are using the Novell LDAP Provider to allow our server application
    be configured in LDAP mode. One of our clients is experiencing a memory
    leak and we believe that the problem could be related to a "The Security
    ID is not valid" error. When he changes to native Active Directory mode
    the memory leak dissapears (he still gets the "Security ID" error, but
    all works fine). So, we think that the problem caused by the "Security
    ID" error is affecting the Novell Ldap Provider library. He is using a
    Windows 2008 R2 platform.
    My question is: Do you know if these kind of errors are properly
    handled so that resources are released?
    We are using the 2.1.10.1 version of the library.
    Many thanks for you help,
    Luis
    luixrodix
    luixrodix's Profile: http://forums.novell.com/member.php?userid=107647
    View this thread: http://forums.novell.com/showthread.php?t=435894

    ab;2091346 Wrote:
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > Have the exact error message? Is it safe to assume you are querying
    > MAD
    > and not eDirectory? I make that assumption because you mentioned
    > SIDs.
    >
    > Good luck.
    >
    > Yes the message is: "The Security ID structure is invalid". It is the
    > error 1337 of Windows and cannot be fixed manually since SIDs cannot be
    > modified manually.
    >
    >
    > When the client has configured our tool as Active Directory via LDAP
    > (using the Novell Ldap library) the error is not logged anywhere (that's
    > another reason for thinking that the library is not handling the error
    > correctly) and the application has memory leaks everytime the AD server
    > is queried, but when they use the same Active Directory but in a pure AD
    > configuration (using System.DirectoryServices and Windows API directly)
    > the error is logged and the memory of the application remains stable.
    >
    > I asked the client to fix the Security ID problem, trying to find the
    > user(s) whose SID are wrong and re-creating them, but if the Novell.Ldap
    > library is not handling this error correctly the potential problem is
    > still there.
    >
    >
    >
    >
    >
    > On 03/30/2011 08:36 AM, luixrodix wrote:
    > >
    > > I mean, everytime a query is sent to the LDAP server an Invalid SID
    > is
    > > reported, and some resources are not released. We think that the
    > problem
    > > could be in the LDAP Novell library.
    > >
    > >
    > -----BEGIN PGP SIGNATURE-----
    > Version: GnuPG v2.0.15 (GNU/Linux)
    > Comment: Using GnuPG with Mozilla - 'Enigmail: A simple interface for
    > OpenPGP email security' (http://enigmail.mozdev.org/)
    >
    > iQIcBAEBAgAGBQJNk2bcAAoJEF+XTK08PnB5K1oP/RB5AUOUtXi13jS/3bSG0wVC
    > uErEfdqBj6R7yliZ8oqkLApQXzEomMwmSRwa4K6v+Rj1MDFBW+ nBFTOv4aHVgq53
    > ANslfM0inboZIxuQxBEhB/5HD062s4yGHTgL81LgeKdYyZvx0np6zmgDOVA/Ogx5
    > GS0nQfAhUZ+tAlgrhzRj3FB9WaamSQsdmEbXCTLjIrhy2FjH14 RidAmY0civvAsw
    > 5EoAlPe56JzQWhdzyIMhodVB2lIa2b+ttoKY7+Q35PsW2KJ3zl +O2MgHBdBtGUOQ
    > DekIR3h5kOjsRGAia8Td1eqSjziNB04fBcjR++B1vLuzE7YSGR mfRVAofOdjtlsR
    > lQ7sRX5Wg9cKN0KniMmvgrKaMqYcnl3wGgvhbVDA+vgriOxnRt PRssrTckrRaOcU
    > KvE3efwvgbdWeRNdfVAwU2qMPrsEA051XBtRKCclv5Ebi6AgwZ uuT3rYRm2Ycusy
    > TebrcX+YkiCZE+GYfULzN2KDUoxCbB85xBGwsg9Iz2/nTt6mkHT0+KqNM713uNJX
    > OqtJJP1fvfw6JMeQW5rS0VrTl2yGncJHf+cvrp0cXx8l+CJkB3 X7phZ5N0c1ttTc
    > 9cPCT+WuC7lCn4QviC8QlmZUYfbGDZmYbxm4ewUalB4J6uoBgy HPSbDITHXIeTz9
    > ISovMI9iFXzrS+Cjd7dk
    > =HEVD
    > -----END PGP SIGNATURE-----
    luixrodix
    luixrodix's Profile: http://forums.novell.com/member.php?userid=107647
    View this thread: http://forums.novell.com/showthread.php?t=435894

  • FlushBeforeQueries Feature cause memory leak?

    Hello,
    I am testing out the latest release 3.2.4 with the "FlushBeforeQueries"
    behavior enabled. But ran into a few problems:
    1) First I tried it with action which imports a big business object (in
    XML format - about 2.5MB) into our system with following configuration:
    javax.jdo.option.IgnoreCache: false
    kodo.ConnectionRetainMode: transaction
    kodo.FlushBeforeQueries: with-connection
    However, I got a java.lang.OutOfMemoryError;
    By putting in some print-outs, I managed to locate where the error comes
    from - from the call "tx.commit();".
    2) Then I tried to import a smaller object (in XML format again about
    1.1MB); and interestingly, it succeeds.
    3) So I start to tweak with the configuration:
    set the kodo.FlushBeforeQueries to true,
    kodo.ConnectionRetainMode to persistence-manager or on-demand;
    After trying quite a few combination, the only one which suppose to
    enable the "FlushBeforeQueries" behavior is:
    javax.jdo.option.IgnoreCache: false
    kodo.ConnectionRetainMode: on-demand
    kodo.FlushBeforeQueries: with-connection
    However, with this setting, the kodo's log from kodo.Query says the
    query has to be run in the memory and the whole object extent has to be
    loaded due to setting: "javax.jdo.option.IgnoreCache=false and
    kodo.FlushBeforeQueries=flase", so the query will be very slow. And this
    log is correct - the system runs much much slower.
    So, my questions are:
    1) Has anyone observe the same as I did? if so, how did you resolve it?
    2) Since the importing of smaller object (less persisted objects being
    created) succeed, but bigger one fails, is it possible there is some
    memory leaking associated with this FlushBeforeQueries thing?
    3) According to the document from Kodo, configuration:
    javax.jdo.option.IgnoreCache: false
    kodo.ConnectionRetainMode: on-demand
    kodo.FlushBeforeQueries: with-connection
    should enable flushBeforeQuery, but why it is not in this release? or do
    I miss something?
    Thanks,
    Tao

    Whatever it is, I have sent a test case yesterday morning. But there is
    no answer yet - I am not even know if they got the code.
    Once I get the explanation, or the solution from Kodo support team, I
    will share it with you guys interested.
    cheers,
    Tao
    Abe White wrote:
    >
    I'm interested in hearing about this since we also use this feature.Well, the short answer is that we don't think it's memory leak in Kodo.

  • Flash cause Memory leak problem under IE

    I have encountered a problem when running a flash with
    countdown scripts inside under IE.
    The IE in memory will become bigger and bigger and IE will
    finally eat up 50% of my processing time.
    My script cannot be officially go online of this problem.
    Similar flash by other with the same problem in IE:
    http://www.zsg.com/
    *** additional info: the leak will reset if the browser is
    being minimized.
    Can any one help?
    Thanks a lot!
    P.S My countdown script play no problem with Firefox 2.0.0.14
    Flash player 9.124.0
    IE version 7.0.5730.13
    OS: Win XP with SP2
    My scripts is just a simple onEnterFrame with calculation
    inside until the difference between current time and target time is
    <=0(target time - difference time)
    Thanks a lot!

    Which process is not releasing memory? Which thread within that process? What do the process monitoring programs from Technet/SysInternals (see
    https://technet.microsoft.com/en-us/sysinternals/bb795533.aspx ) show about the memory that is not being released?
    There may be memory leaks in Coded UI but more likely the leaks are in the test cases and the way they use Coded UI. I think you need to do some more investigation and show its results before getting much more than just general advice here.
    Regards
    Adrian

  • [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

  • Does OutputStream.write() has a memory leak on Linux?

    I write a piece of java code to create 500K small files (average 40K each) on CentOS. The original code is like this:
         package MyTest;
         import java.io.*;
         public class SimpleWriter {
    public static void main(String[] args) {
      String dir = args[0];
      int fileCount = Integer.parseInt(args[1]);
      String content="@#$% SDBSDGSDF ASGSDFFSAGDHFSDSAWE^@$^HNFSGQW%#@&$%^J#%@#^$#UHRGSDSDNDFE$T#@$UERDFASGWQR!@%!@^$#@YEGEQW%!@%!!GSDHWET!^";
      StringBuilder sb = new StringBuilder();
      int count = 40 * 1024 / content.length();
      int remainder = (40 * 1024) % content.length();
      for (int i=0; i < count; i++)
       sb.append(content);
      if (remainder > 0)
       sb.append(content.substring(0, remainder));
      byte[] buf = sb.toString().getBytes();
      for (int j=0; j < fileCount; j++)
       String path = String.format("%s%sTestFile_%d.txt", dir, File.separator, j);
       try{
        BufferedOutputStream fs = new BufferedOutputStream(new FileOutputStream(path));
        fs.write(buf);
        fs.close();
       catch(FileNotFoundException fe)
        System.out.printf("Hit filenot found exception %s", fe.getMessage());
       catch(IOException ie)
        System.out.printf("Hit IO exception %s", ie.getMessage());
    You can run this by issue following command:
      java -jar SimpleWriter.jar my_test_dir 500000
    I thought this is a simple code, but then I realize that this code is using up to 14G of memory.  I know that because when I use free -m to check the memory, the free memory kept dropping, until my 15G memory VM only had 70 MB free memory left.  I compiled this using Eclipse, and I compile this against JDK 1.6 and then JDK1.7. The result is  the same.  The funny thing is that, if I comment out fs.write(), just open and close the stream, the memory stabilized at certain point.  Once I put fs.write() back, the memory allocation just go wild.  500K 40KB files is about 20G.  It seems Java's stream writer never deallocate its buffer during the operation.
    I once thought java GC does not have time to clean.  But this make no sense since I closed the file stream for every file.  I even transfer my code into C#, and running under windows, the same code producing 500K 40KB files with memory stable at certain point, not taking 14G as under CentOS.  At least C#'s behavior is what I expected, but I could not believe Java perform this way.  I asked my colleague who were experienced in java.  They could not see anything wrong in code, but could not explain why this happened.  And they admit nobody had tried to create 500K file in a loop without stop.
    I also searched online and everybody says that the only thing need to pay attention to, is close the stream, which I did.
    Can anyone help me to figure out what's wrong?
    Can anybody also try this and tell me what you see?
    BTW, some people in online community tried the code on Windows and it seemed to worked fine.  I didn't tried it on windows.  I only tried in Linux as I thought that where people use Java for.  So, it seems this issue happened on Linux).
    I also did the following to limit the JVM heap, but it take no effects
        java -Xmx2048m -jar SimpleWriter.jar my_test_dir 500000

    Good point, I actually run cat /proc/meminfo. And I got the following.  Why I have so big of Inactive(file) allocation?
    MemTotal:       15239492 kB
    MemFree:           83424 kB
    Buffers:           76012 kB
    Cached:         13920152 kB
    SwapCached:            0 kB
    Active:           391104 kB
    Inactive:       14181268 kB
    Active(anon):     288124 kB
    Inactive(anon):   288268 kB
    Active(file):     102980 kB
    Inactive(file): 13893000 kB
    Unevictable:           0 kB
    Mlocked:               0 kB
    SwapTotal:        500432 kB
    SwapFree:         500432 kB
    Dirty:           2568700 kB
    Writeback:          6064 kB
    AnonPages:        576292 kB
    Mapped:             9884 kB
    Shmem:               140 kB
    Slab:             472340 kB
    SReclaimable:     421692 kB
    SUnreclaim:        50648 kB
    KernelStack:        1192 kB
    PageTables:         4132 kB
    NFS_Unstable:          0 kB
    Bounce:                0 kB
    WritebackTmp:          0 kB
    CommitLimit:     8120176 kB
    Committed_AS:     835900 kB
    VmallocTotal:   34359738367 kB
    VmallocUsed:       38908 kB
    VmallocChunk:   34359687700 kB
    HardwareCorrupted:     0 kB
    AnonHugePages:         0 kB
    HugePages_Total:       0
    HugePages_Free:        0
    HugePages_Rsvd:        0
    HugePages_Surp:        0
    Hugepagesize:       2048 kB
    DirectMap4k:    15728640 kB
    DirectMap2M:           0 kB
    BTW, my test used up all the memory again, and free -m show this
                 total       used       free     shared    buffers     cached
    Mem:         14882      14805         76          0         80      13583
    -/+ buffers/cache:       1142      13740
    Swap:          488          0        488
    Any hint what's going on?

  • Using KineticJS in Firefox causes memory leak (page works good in all other browsers, including Firefox Beta for Android)

    Hi,
    You can visit http://brandy.pararuk.com and see just 15 flying comets animated with KineticJS library.
    When I run it (viewing Windows Task Manager) I see that firefox.exe consumes 100Mb of memory every second up to full avaliable memory and hangs on Windows.
    I've tested this page also on desktop with: Chrome, Safari, IE9 and on my Android tablet with: Firefox Beta, Chrome and Android browser - page works good everywhere, except of desktop Firefox.
    Thank you for help.

    Did you try to disable extensions like Firebug?
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Datagrid column in module causing memory leak

    Hi All
    I'm having trouble with a DataGrid column preventing a module from being release properly. I can't imagine this is the intended behaviour.
    Using this simple test case, a WindowedApplication and an mx:Module I wonder if anyone else can reproduce this problem. The issue goes away if you simply comment out the GridColumn Instance.
    Can anyone offer any advice?
    Many thanks
    James
    DataGridTest.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           xmlns:mx="library://ns.adobe.com/flex/mx">
        <fx:Script>
            <![CDATA[
                import mx.core.IVisualElement;
                import mx.events.ModuleEvent;
                import mx.modules.IModuleInfo;
                import mx.modules.ModuleManager;
                private var assetModule:IModuleInfo;
                protected function load_clickHandler(event:MouseEvent):void
                    assetModule = ModuleManager.getModule('DataGridTestModule.swf');
                    assetModule.addEventListener("ready", getModuleInstance);
                    assetModule.load();
                public function getModuleInstance(event:ModuleEvent):void
                    var sm:DisplayObject = assetModule.factory.create() as DisplayObject;
                    sm.addEventListener("close", closeModule);
                    contentHolder.addElement(sm as IVisualElement);
                private function closeModule(event:Event):void
                    event.target.removeEventListener("close", closeModule);
                    contentHolder.removeElement(event.target as IVisualElement);
                    assetModule.unload();
                    assetModule = null;
            ]]>
        </fx:Script>
        <s:VGroup width="100%" height="100%">
            <s:HGroup >
                <s:Button id="load" label="Load" click="load_clickHandler(event)"/>
            </s:HGroup>
            <s:BorderContainer id="contentHolder" width="100%" height="100%"/>
        </s:VGroup>
    </s:WindowedApplication>
    DataGridTestModule.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
                          xmlns:s="library://ns.adobe.com/flex/spark"
                          xmlns:mx="library://ns.adobe.com/flex/mx"
                          layout="absolute" xmlns:components="components.*">
        <fx:Script>
            <![CDATA[
                protected function close_clickHandler(event:MouseEvent):void
                    dispatchEvent(new Event('close', true, false))
            ]]>
        </fx:Script>
        <s:BorderContainer id="contacts"
                           width="100%" height="100%"
                           backgroundAlpha="0"
                           borderVisible="false">
            <s:layout>
                <s:VerticalLayout/>
            </s:layout>
            <s:Button id="close" label="Close" click="close_clickHandler(event)"/>
            <s:DataGrid id="queries" >
                <s:columns>
                    <s:ArrayList>
                        <s:GridColumn/> <!-- Comment out this GridColumn instance to see the leak disappear -->
                    </s:ArrayList>
                </s:columns>
            </s:DataGrid>
        </s:BorderContainer>
    </mx:Module>

    OK, So I've done some more testing. Creating the GridColumn in AS during the creationComplete event is a slight improvement. It seems to allow the DataGrid and the Module be GC'd, but it's still leaking memory somewhere. I just can't get my head around the Profiler. Also, it's going to be a massive headache if we have to rewrite our application to create all the GridColumns in AS. Surely this shouldn't be necessary?
    New test case below:
    DataGridTest.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           xmlns:mx="library://ns.adobe.com/flex/mx">
        <fx:Script>
            <![CDATA[
                import mx.collections.ArrayList;
                import mx.core.IVisualElement;
                import mx.events.ModuleEvent;
                import mx.modules.IModuleInfo;
                import mx.modules.ModuleManager;
                import spark.components.gridClasses.GridColumn;
                private var assetModule:IModuleInfo;
                private var sm:DisplayObject;
                protected function load_clickHandler(event:MouseEvent):void
                    assetModule = ModuleManager.getModule('DataGridTestModule.swf');
                    assetModule.addEventListener("ready", getModuleInstance);
                    assetModule.load();
                public function getModuleInstance(event:ModuleEvent):void
                    sm = assetModule.factory.create() as DisplayObject;
                    sm.addEventListener("close", closeModule);
                    contentHolder.addElement(sm as IVisualElement);
                private function closeModule(event:Event):void
                    event.target.removeEventListener("close", closeModule);
                    contentHolder.removeElement(event.target as IVisualElement);
                    assetModule.unload();
                    assetModule = null;
            ]]>
        </fx:Script>
        <s:VGroup width="100%" height="100%">
            <s:HGroup >
                <s:Button id="load" label="Load" click="load_clickHandler(event)"/>
            </s:HGroup>
            <s:BorderContainer id="contentHolder" width="100%" height="100%"/>
        </s:VGroup>
    </s:WindowedApplication>
    DataGridTestModule.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
                          xmlns:s="library://ns.adobe.com/flex/spark"
                          xmlns:mx="library://ns.adobe.com/flex/mx"
                          creationComplete="module1_creationCompleteHandler(event)"
                          layout="absolute" xmlns:components="components.*">
        <fx:Script>
            <![CDATA[
                import flash.utils.setTimeout;
                import mx.collections.ArrayList;
                import mx.events.FlexEvent;
                import spark.components.gridClasses.GridColumn;
                 [Bindable]
                private var _col:ArrayList = new ArrayList();
                protected function close_clickHandler(event:MouseEvent):void
                    dispatchEvent(new Event('close', true, false))
                protected function module1_creationCompleteHandler(event:FlexEvent):void
                    var gc:GridColumn = new GridColumn();
                    gc.headerText = 'Test Column';
                    _col.addItem(gc);
            ]]>
        </fx:Script>
        <s:BorderContainer width="100%" height="100%">
            <s:layout>
                <s:VerticalLayout/>
            </s:layout>
            <s:Button id="close" label="Close" click="close_clickHandler(event)"/>
            <s:DataGrid id="queries" columns="{_col}"/>
        </s:BorderContainer>
    </mx:Module>

Maybe you are looking for

  • Connecting computers

    I just acquired a G3 MT for my daughter from a friend. I have two quick questions - 1. There was no manual or information about how to "use" the Mac. I have only had Microsoft based PC's so the user interface, etc. is very unfamiliar. Are there any m

  • Mac Pro Freeze constantly - no kernel panic, no crash reports. Any ideas?

    Dear all, My good ol' Mac Pro (4.1-2009) which has been utterly reliable for years is now driving me cazy. It freezes from time to time (let's say twice a day but sometimes not at all for 2 days in a row) - only possible option is hard reboot. The sc

  • BAPI_BUS2173_SET_STATUS should be able to set user status profile.

    Hi, I need use a workflow to setup user status profile for PHASE and TASK, but I found that the unique easy way to setup the user status profile for PHASE or TASK is manual operation.  I have created a user status profile of the BUS2173 and BUS2175.

  • Image border colors change when DOC convered to PDF

    First off...I have Word 2007 and Acrobat 7 Standard on Windows XP. I tried a trial version of Acrobat 8 for converting PDFs, but it did not resolve all my issues to I'm remote connecting to another computer in the office to create my PDFs. I have to

  • How do I rebuild my desktop, using OS x 8.3?

    How do I rebuild my iMac desktop using OS X 8.3?