Memory leak in a function registered using set_restore_function()

I experience a problem with memory leak caused by the following function:
void RestorePhonemesSet(PhonemesSetStructType &phonemesSet, const void *src) {
char p = (char ) src;
memcpy(&phonemesSet.len, p, sizeof (int));
p += sizeof (int);
memcpy(&phonemesSet.whichFile, p, sizeof (int));
p += sizeof (int);
memcpy(&phonemesSet.whichPosition, p, sizeof (int));
p += sizeof (int);
phonemesSet.phonemes = (int *)malloc(sizeof(int)*phonemesSet.len);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here the problematic code
memcpy(phonemesSet.phonemes, p, sizeof (int) * phonemesSet.len);
This function is registered using a following call: DbstlElemTraits<PhonemesSetStructType>::instance()->set_restore_function(RestorePhonemesSet);
The culprit it the malloc memory allocation. If I leave out the malloc the program crashes. If I free the phonemeSet.phonemes memory segment at the end of the restore function I lost data, and if I use the malloc there is a large memory leak while reading every record from the database.
What should I do to prevent the memory leak?
Regards,
markur
Edited by: 904259 on 2011-12-24 05:42

the solution is using the memory allocated for p, no need to allocate new memory space for the variable: the problematic line should look like .phonemes = (int *)p;
the memcpy function in the following line is thus superfluous.
Edited by: 904259 on 2011-12-24 05:43

Similar Messages

  • Memory leak with callback function

    Hi,
    I am fairly new to LabWindows and the ninetv library, i have mostly been working with LabVIEW.
    I am trying to create a basic (no GUI) c++ client that sets up subscriptions to several network variables publishing DAQ data from a PXI.
    The data for each variable is sent in a cluster and contains various datatypes along with a large int16 2D array for the data acquired(average array size is 100k in total, and the average time between data sent is 10ms). I have on average 10 of these DAQ variables.
    I am passing the same callback function as an arguement to all of these subscriptions(CNVCreateSubcription).
    It reads all the correct data, but i have one problem which is that i am experiencing a memory leak in the callback function that i pass to the CNVCreateSubscription.
    I have reduced the code one by one line and found the function that actually causes the memory leak, which is a CNVGetStructFields(). At this point in the program the data has still not been passed to the clients variables.
    This is a simplified version of the callback function, where i just unpack the cluster and get the data (only showing from one field in the cluster in the example, also not showing the decleration).
    The function is passed into to the subscribe function, like so:
    static void CNVCALLBACK SubscriberCallback(void * handle, CNVData data, void * callbackData);
    CNVCreateSubscriber (url.c_str(), SubscriberCallback, NULL, 0, CNVWaitForever, 0 , &subscriber);
    static void CNVCALLBACK SubscriberCallback(void * handle, CNVData data, void * callbackData)
    int16_t daqValue[100000];
    long unsigned int nDims;
    long unsigned int daqDims[2];
    CNVData fields[1];
    CNVDataType type;
    unsigned short int numFields;
    CNVGetDataType(data, &type, &nDims);
    CNVGetNumberOfStructFields (data, &numFields);
    CNVGetStructFields (data, fields, numFields); // <-------HERE IS THE PROBLEM, i can comment out the code after this point and it still causes a memory leak.
    CNVGetDataType(fields[0], &type, &nDims);
    CNVGetArrayDataDimensions(fields[0], nDims, acqDims);
    CNVGetArrayDataValue(fields[0], type, daqValue, daqDims[0]*daqDims[1]);
    CNVDisposeData(data);
    At the average settings i use all my systems memory (4GB) within one hour. 
    My question is, have any else experienced this and what could the problem/solution to this be?
    Thanks.
    Solved!
    Go to Solution.

    Of course.....if it is something i hate more than mistakes, it is obvious mistakes.
    Thank you for pointing it out, now everything works

  • Memory Leak in terminateConnection() function. How to resolve it ???

    Hi,
    We are facing a memory leak issue in terminateConnection() function. Here is a sample code regarding that. We have run around 1.5 hours simultaneously and it was consuming around 250MB for this simple program. How could I resolve this problem ?
    bool test()
        string userName = "mapserver";
        string password = "a";
        string connectString = "//localhost:1521/orcl";
        string query = "SELECT GEOMETRY AS GEOM FROM AG_WATER";
        Environment *env = Environment::createEnvironment(Environment::OBJECT);
            Connection *conn;
            Statement *stmt;
            ResultSet *rs;
            try{
                conn = env->createConnection(userName, password, "");
            catch (SQLException ex) {
                printf("ORACLE execution error: [Error Code : %d] : %s\n", ex.getErrorCode(), ex.getMessage().c_str());
                return false;
            env->terminateConnection(conn);
            stmt = NULL;
            conn = NULL;
            rs = NULL;
        Environment::terminateEnvironment(env);
        return true;
    int main()
        OracleResultSet pResultSet;
        while (true) {
            test();
        return 0;
    Does any body help me to find out this problem ???

    This is not a web dynpro related question.  Please restrict the questions in this forum to the Web Dynpro ABAP topic.

  • Memory leak under GNU/Linux when using exec()

    Hi,
    We detected that our application was taking all the free memory of the computer when we were using intensively and periodically the method exec() to execute some commands of the OS. The OS of the computer is a GNU/Linux based OS.
    So, in order to do some monitoring we decided to wrote a simple program that called exec() infinite number of times, and using the profiler tool of Netbeans we saw a memory leak in the program because the number of surviving generations increased during all the execution time. The classes that have more surviving generations are java.lang.ref.Finalizer, java.io.FileDescriptor and byte[].
    We also decided to test this simple program using Windows, and in that OS we saw that the memory leak disappeared: the number of surviving generations was almost stable.
    I attach you the code of the program.
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    public class testExec
        public static void main(String args[]) throws IOException, InterruptedException
            Runtime runtime = Runtime.getRuntime();
            while (true)
                Process process = null;
                InputStream is = null;
                InputStreamReader isr = null;
                BufferedReader br = null;
                try
                    process = runtime.exec("ls");
                    //process = runtime.exec("cmd /c dir");
                    is = process.getInputStream();
                    isr = new InputStreamReader(is);
                    br = new BufferedReader(isr);
                    String line;
                    while ((line = br.readLine()) != null)
                        System.out.println(line);
                finally
                    process.waitFor();
                    if (is != null)
                        is.close();
                    if (isr != null)
                        isr.close();
                    if (br != null)
                        br.close();
                    if (process != null)
                        process.destroy();
    }¿Is anything wrong with the test program we wrote? (we know that is not usual to call infinite times the command ls/dir, but it's just a test)
    ¿Why do we have a memory leak in Linux but not in Windows?
    I will appreciate any help or ideas. Thanks in advance.

    Hi Joby,
    From our last profiling results, we haven't found yet a proper solution. We think that probably the problem is caused by the byte[]'s/FileInputStreams created by the class UNIXProcess that manage the stdin, stdout and stderr streams. It seems that these byte arrays cannot be removed correctly by the garbage collector and they become bigger and bigger, so at the end they took all the memory of the system.
    We downloaded the last version of OpenJDK 6 (build b19) and modified UNIXProcess.java.linux so when we call its method destroy(), we assign to null those streams. We did that because we wanted to indicate to the garbage collector that these objects could be removed, as we saw that the close() methods doesn't do anything on their implementation.
    public void destroy() {
         // There is a risk that pid will be recycled, causing us to
         // kill the wrong process!  So we only terminate processes
         // that appear to still be running.  Even with this check,
         // there is an unavoidable race condition here, but the window
         // is very small, and OSes try hard to not recycle pids too
         // soon, so this is quite safe.
         synchronized (this) {
             if (!hasExited)
              destroyProcess(pid);
            try {
                stdin_stream.close();
                stdout_stream.close();
                stderr_stream.close();
                // LINES WE ADDED
                stdin_stream = null;
                stdout_stream = null;
                stderr_stream = null;
            } catch (IOException e) {
                // ignore
                e.printStackTrace();
        }But this didn't work at all. We saw that we were able to execute for a long time our application and that the free memory of the system wasn't decreasing as before, but we did some profiling with this custom JVM and the test application and we still see more or less the same behaviour: lots of surviving generations, at some point increase of the used heap to the maximum allowed, and finally the crash of the test app.
    So sadly, we still don't have a solution for that problem. You could try to compile OpenJDK 6, modify it, and try it with your program to see if the last version works for you. Compiling OpenJDK 6 in Linux is quite easy: you just have to download the source and the binaries from here and configure your environment with something like this:
    export ANT_HOME=/opt/apache-ant-1.7.1/
    export ALT_BOOTDIR=/usr/lib/jvm/java-6-sun
    export ALT_OUTPUTDIR=/tmp/openjdk
    export ALT_BINARY_PLUGS_PATH=/opt/openjdk-binary-plugs/
    export ALT_JDK_IMPORT_PATH=/usr/lib/jvm/java-6-sun
    export LD_LIBRARY_PATH=
    export CLASSPATH=
    export JAVA_HOME=
    export LANG=C
    export CC=/usr/bin/gcc-4.3
    export CXX=/usr/bin/g++-4.3Hope it helps Joby :)
    Cheers.

  • Memory Leak on General Block when using Java Script

    Hi,
    I have a web view, that runs a html within the html there is a javascript which has a third party object this object displays some data and grows dynamically every time I invoke this object to grow I see in Instrument monitor whole bunch of Generalblock-256 ( 256 Bytes ) memory leak, I was wondering how can I manage this memory, I know in java script if we assign null to an object java will release it, but it's already reported the leak before I assign the object to null.
    Is there any way I can use let's say by NSAutoReleasePool.
    Thanks.

    The Memory leak is pretty much gone, with new release of OS 2.2.1 as apple has done better memory management for safari.

  • Memory Leak in web application created using j2ee

    Hi,
    Our company has one web application, provided by "X" vendor. this application has many JSPs and many TLDs used. The basic behaviour of the apoplication is to connect to the database (Oracle) get the information and show it to the user.
    We deployed this web application in Tomcat 5.0.25 in the windows environment. One thing we observed here is, when we login to the application the tomcat5.exe process increses its memory. and when we logout, it does not come down to the original position. similar things happen when we search for some of the data using there provided searches.
    We have some code developed which uses httpclient to login to this web application (created for performace testing). This code initially logs in 50 users which goes fine, then logs in 100 users which also goes fine but after this 100 users we ran the code for 50 users agian but this time it threw OutOfmemory exception:Java heap space error.
    we are observing the memory in the Task Manager in windows.
    Can anyone tell me what could be the cause of this? is it the web application causing problem or is tomcat caching some pages into the memory and is not releasing them?

    Hi,
    Few questions!
    1> Have you tweaked your jvm?
    2> What are the values given for Xms and Xmx?
    3> What is the size of XX:MaxPermGen?
    4> How much RAM is available on the system where you have deployed your app?
    5> Are you using pre-complied JSPs for faster response?
    6> Which JDK are you using?
    7> Have you tried using latest version of Tomcat?
    8> If these doesnt help, use any profiler to find the leak. <JProfiler, JVMTI, YourKit profiler etc>
    I hope answering these questions would help you :)
    njoy!

  • Memory leak in explict\images\content\used

    Since about a week ago my girlfriend's Firefox 19.0.2 started to crash with low memory message. She's using a laptop with 3 gig of memory and Windows 7 32. Her add-ons are adblock, WeatherBug and some spellcheckers.
    I reinstalled her browser and also installed Memory Fox plugin. It didn't help. Crashes occur once in one or two days after several hours of browsing.
    I asked her to save the "about:memory" page when the low memory message appears. These are the first lines:
    1,347.68 MB (100.0%) -- explicit
    ├──1,007.93 MB (74.79%) -- images
    │ ├──1,007.71 MB (74.77%) -- content
    │ │ ├──1,007.65 MB (74.77%) -- used
    │ │ │ ├────601.40 MB (44.62%) ── raw
    │ │ │ ├────361.11 MB (26.79%) ── uncompressed-nonheap
    │ │ │ └─────45.14 MB (03.35%) ── uncompressed-heap
    │ │ └──────0.06 MB (00.00%) ++ unused
    │ └──────0.22 MB (00.02%) ++ chrome
    She also sent me the page just after she started Firefox (with her pinned tabs) and there are no such memory figures.
    Unfortunately I can't be more specific. She can't say if she changed something recently and she's also unable to cause it to happen when I am there.

    The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information.
    Note: ''This will cause you to lose any Extensions, Open websites, and some Preferences.''
    To Reset Firefox do the following:
    #Go to Firefox > Help > Troubleshooting Information.
    #Click the "Reset Firefox" button.
    #Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    #Firefox will open with all factory defaults applied.
    Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
    Did this fix your problems? Please report back to us!

  • Memory leak? amd 64 bit using 1.4.2_03 program runs fine on other computers

    I have a program that runs fine on a red hat linux desktop and a pentium 1.6ghz xp pro laptop but on my amd 64 bit 3400+ xp pro desktop after ~20 seconds it slows to a crawl. i was originally using j2sdk1.4.2_04 but noticed this was not available for download anymore so i switched to j2sdk1.4.2_03 but have the same problem. my laptop is using j2sdk1.4.2_03. im not sure what the red hat linux machine is using. this is a starfield simulator and when it starts to slow all the stars turn gray and its like the drawLine is not working right either. anyone have any ideas? code is below
    import java.awt.*;
    import java.awt.event.WindowListener;
    import java.awt.event.WindowEvent;
    import java.util.*;
    import javax.swing.*;
    import java.io.*;
    class StarfieldWindowListener implements WindowListener
    public void windowActivated( WindowEvent e ) {}
    public void windowClosed( WindowEvent e ) {}
    public void windowClosing( WindowEvent e )
    System.exit(0);
    public void windowDeactivated( WindowEvent e ) {}
    public void windowDeiconified( WindowEvent e ) {}
    public void windowIconified( WindowEvent e ) {}
    public void windowOpened( WindowEvent e ) {}
    public class StarfieldSimulator
         public static void main (String args[])
              JFrame frame = new JFrame ("Starfield Simulator");
              frame.getContentPane ().setLayout (new BorderLayout ());
              if (args.length == 0) frame.getContentPane ().add (new Starfield (500));
              else frame.getContentPane ().add (new Starfield (Integer.parseInt (args[0])));
    frame.addWindowListener(new StarfieldWindowListener());
              frame.setSize (1024, 768);
              frame.show ();
    class Point3D
         public double x, y, z;
    public float r, g, b;
    public Color c;
         public Point3D (double x, double y, double z)
    Random random = new Random ();
              this.x = x;
              this.y = y;
              this.z = z;
    r = random.nextFloat();
    g = random.nextFloat();
    b = random.nextFloat();
    c = new Color( r, g, b );
    class Starfield extends JComponent
         protected boolean first;
         protected Point3D points[][];
         protected Random random;
         private int trail = 20;
    private double rot = .0005, co = Math.cos( rot ), si = Math.sin( rot );
         public Starfield (int numPoints)
    //RepaintManager repaintManager = RepaintManager.currentManager(this); repaintManager.setDoubleBufferingEnabled(false);
              first = true;
              random = new Random ();
              points = new Point3D[numPoints][trail];
              for( int y = 0; y < numPoints; ++y )
                   for( int x = 1; x < trail; ++x )
                        points[y][x] = new Point3D( 0, 0, 0 );
              for (int index = 0; index < numPoints; index++)
                   points[index][0] = new Point3D ((random.nextDouble () - 0.5) * 2.0, (random.nextDouble () - 0.5) * 2.0, (random.nextDouble () - 0.5) * 2.0);
         public void paint (Graphics g)
    //DebugGraphics g = new DebugGraphics(g1);
    int i;
              int halfWidth = getWidth () / 2;
              int halfHeight = getHeight () / 2;
              g.setColor (Color.black);
              g.fillRect (0, 0, getWidth (), getHeight ());
              int pointsLength = points.length;
              for (int index = 0; index < pointsLength; index++)
                   for( i = trail - 1; i >= 1; --i )
                        points[index] = points[index][i - 1];
    if( points[index][0].z <= 0.0 )
    while (points[index][0].z <= 0.0) points[index][0] = new Point3D ((random.nextDouble () - 0.5) * 2.0, (random.nextDouble () - 0.5) * 2.0, (random.nextDouble () - 0.5) * 2.0);
    points[index][0].r = random.nextFloat();
    points[index][0].g = random.nextFloat();
    points[index][0].b = random.nextFloat();
    for( i = 1; i < trail; ++i )
    points[index][i].x =points[index][i].y = points[index][i].z = 0;
    g.setColor (points[index][0].c);
                   for( i = 0; i < trail; ++i )
                        points[index][i].x = points[index][i].x * co - points[index][i].y * si;
                        points[index][i].y = points[index][i].y * co + points[index][i].x * si;
    int sx1, sy1, sx2, sy2;
    sx1 = (int) ((points[index][0].x * halfWidth) / ((points[index][0].z) * 10.0)) + halfWidth;
    sy1 = (int) ((points[index][0].y * halfHeight) / ((points[index][0].z) * 10.0)) + halfHeight;
    if( points[index][(trail - 1)].z == 0 )
    g.drawRect( sx1, sy1, 1, 1 );
    else
    sx2 = (int) ((points[index][(trail - 1)].x * halfWidth) / ((points[index][(trail - 1)].z + .0005 * (trail - 1)) * 10.0)) + halfWidth;
    sy2 = (int) ((points[index][(trail - 1)].y * halfHeight) / ((points[index][(trail - 1)].z + .0005 * (trail - 1)) * 10.0)) + halfHeight;
    g.drawLine( sx1, sy1, sx2, sy2 );
    points[index][0].r = (float) Math.min ( points[index][0].r + .00005, 1.0 );
    points[index][0].g = (float) Math.min ( points[index][0].g + .00005, 1.0 );
    points[index][0].b = (float) Math.min ( points[index][0].b + .00005, 1.0 );
    points[index][0].c = new Color( points[index][0].r, points[index][0].g, points[index][0].b );
                   points[index][0].z -= 0.0025;
    try {
    Thread.sleep(1);
    } catch (InterruptedException e) {
    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    repaint();

    doesnt ANYONE have an answer?? please?Apparently not. If the answer involves us typing in your program, understanding it, debugging it, etc., hey, we all have jobs, too. We can answer specific questions ("How do I do <some specific task>?" or "I tried this and that <specific task> but ran into <specific problem>"). But we don't have all day to debug everyone's programs.
    * First of all, use the code formatting markup around your code (See the Formatting Help link).
    * Secondly, tell us what you have tried - have you looked at your Task Manager and recorded your program's size? Compare it on the machines where it runs well, and the one where it doesn't.

  • Free memory after using GetRS232ErrorString() to avoid memory leak?

    Hello,
    Is it necessary to free memory after using function GetRS232ErrorString() to avoid memory leak?
    Example 1:
    int main();
    char *strError=NULL;
    strError = GetRS232ErrorString(55); /* just an example for error message */
    free(strError ); /* Do I need to free this pointer? */
    Example 2:
    int main();
    MessagePopup ("Error", GetRS232ErrorString(55)); ; /* Will I get a memory leak with this function call? */
    BR
    Frank

    It's a pity that the documentation is indeed so poor in this case, but testing shows that it always returns the same pointer, no matter the error code, so it seems to be using an internal buffer and you are not supposed to free the string (but need to copy it before the next call to GetRS232ErrorString if you need to keep the text). It does however return a different pointer for every thread, so atl least it seems to be thread safe.
    Cheers, Marcel 

  • Huge memory leaks in using PL/SQL tables and collections

    I have faced a very interesting problem recently.
    I use PL/SQL tables ( Type TTab is table of ... index by binary_integer; ) and collections ( Type TTab is table of ...; ) in my packages very widely. And have noticed avery strange thing Oracle does. It seems to me that there are memory leaks in PGA when I use PL/SQL tables or collections. Let me a little example.
    CREATE OR REPLACE PACKAGE rds_mdt_test IS
    TYPE TNumberList IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
    PROCEDURE test_plsql_table(cnt INTEGER);
    END rds_mdt_test;
    CREATE OR REPLACE PACKAGE BODY rds_mdt_test IS
    PROCEDURE test_plsql_table(cnt INTEGER) IS
    x TNumberList;
    BEGIN
    FOR indx IN 1 .. cnt LOOP
    x(indx) := indx;
    END LOOP;
    END;
    END rds_mdt_test;
    I run the following test code:
    BEGIN
    rds_mdt_test.test_plsql_table (1000000);
    END;
    and see that my session uses about 40M in PGA.
    If I repeat this example in the same session creating the PL/SQL table of smaller size, for instance:
    BEGIN
    rds_mdt_test.test_plsql_table (1);
    END;
    I see again that the size of used memory in PGA by my session was not decreased and still be the same.
    The same result I get if I use not PL/SQL tables, but collections or varrays.
    I have tried some techniques to make Oracle to free the memory, for instance to rewrite my procedure in the following ways:
    PROCEDURE test_plsql_table(cnt INTEGER) IS
    x TNumberList;
    BEGIN
    FOR indx IN 1 .. cnt LOOP
    x(indx) := indx;
    END LOOP;
    x.DELETE;
    END;
    or
    PROCEDURE test_plsql_table(cnt INTEGER) IS
    x TNumberList;
    BEGIN
    FOR indx IN 1 .. cnt LOOP
    x(indx) := indx;
    END LOOP;
    FOR indx in 1 .. cnt LOOP
    x.DELETE(indx);
    END LOOP;
    END;
    or
    PROCEDURE test_plsql_table(cnt INTEGER) IS
    x TNumberList;
    empty TNumberList;
    BEGIN
    FOR indx IN 1 .. cnt LOOP
    x(indx) := indx;
    END LOOP;
    x := empty;
    END;
    and so on, but result was the same.
    This is a huge problem for me as I have to manipulate collections and PL/SQL tables of very big size (from dozens of thousand of rows to millions or rows) and just a few sessions running my procedure may cause server's fall due to memory lack.
    I can not understand what Oracle reseveres such much memory for (I use local variables) -- is it a bug or a feature?
    I will be appreciated for any help.
    I use Oracle9.2.0.1.0 server under Windows2000.
    Thank you in advance.
    Dmitriy.

    Thank you, William!
    Your advice about using DBMS_SESSION.FREE_UNUSED_USER_MEMORY was very useful. Indeed it is the tool I was looking for.
    Now I write my code like this
    declare
    type TTab is table of ... index binary_integer;
    res TTab;
    empty_tab TTab;
    begin
    res(1) := ...;
    res := empty_tab;
    DBMS_SESSION.FREE_UNUSED_USER_MEMORY;
    end;
    I use construction "res := empty_tab;" to mark all memory allocated to PL/SQL table as unused according to Tom Kyte's advices. And I could live a hapy life if everything were so easy. Unfortunately, some tests I have done showed that there are some troubles in cleaning complex nested PL/SQL tables indexed by VARCHAR2 which I use in my current project.
    Let me another example.
    CREATE OR REPLACE PACKAGE rds_mdt_test IS
    TYPE TTab0 IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
    TYPE TRec1 IS RECORD(
    NAME VARCHAR2(4000),
    rows TTab0);
    TYPE TTab1 IS TABLE OF TRec1 INDEX BY BINARY_INTEGER;
    TYPE TRec2 IS RECORD(
    NAME VARCHAR2(4000),
    rows TTab1);
    TYPE TTab2 IS TABLE OF TRec2 INDEX BY BINARY_INTEGER;
    TYPE TStrTab IS TABLE OF NUMBER INDEX BY VARCHAR2(256);
    PROCEDURE test_plsql_table(cnt INTEGER);
    PROCEDURE test_str_tab(cnt INTEGER);
    x TTab2;
    empty_tab2 TTab2;
    empty_tab1 TTab1;
    empty_tab0 TTab0;
    str_tab TStrTab;
    empty_str_tab TStrTab;
    END rds_mdt_test;
    CREATE OR REPLACE PACKAGE BODY rds_mdt_test IS
    PROCEDURE test_plsql_table(cnt INTEGER) IS
    BEGIN
    FOR indx1 IN 1 .. cnt LOOP
    FOR indx2 IN 1 .. cnt LOOP
    FOR indx3 IN 1 .. cnt LOOP
    x(indx1) .rows(indx2) .rows(indx3) := indx1;
    END LOOP;
    END LOOP;
    END LOOP;
    x := empty_tab2;
    dbms_session.free_unused_user_memory;
    END;
    PROCEDURE test_str_tab(cnt INTEGER) IS
    BEGIN
    FOR indx IN 1 .. cnt LOOP
    str_tab(indx) := indx;
    END LOOP;
    str_tab := empty_str_tab;
    dbms_session.free_unused_user_memory;
    END;
    END rds_mdt_test;
    1. Running the script
    BEGIN
    rds_mdt_test.test_plsql_table ( 100 );
    END;
    I see that usage of PGA memory in my session is close to zero. So, I can judge that nested PL/SQL table indexed by BINARY_INTEGER and the memory allocated to it were cleaned successfully.
    2. Running the script
    BEGIN
    rds_mdt_test.test_str_tab ( 1000000 );
    END;
    I can see that plain PL/SQL table indexed by VARCHAR2 and memory allocated to it were cleaned also.
    3. Changing the package's type
    TYPE TTab2 IS TABLE OF TRec2 INDEX BY VARCHAR2(256);
    and running the script
    BEGIN
    rds_mdt_test.test_plsql_table ( 100 );
    END;
    I see that my session uses about 62M in PGA. If I run this script twice, the memory usage is doubled and so on.
    The same result I get if I rewrite not highest, but middle PL/SQL type:
    TYPE TTab1 IS TABLE OF TRec1 INDEX BY VARCHAR2(256);
    And only if I change the third, most nested type:
    TYPE TTab0 IS TABLE OF NUMBER INDEX BY VARCHAR2(256);
    I get the desired result -- all memory was returned to OS.
    So, as far as I can judge, in some cases Oracle does not clean complex PL/SQL tables indexed by VARCHAR2.
    Is it true or not? Perhaps there are some features in using such way indexed tables?

  • Memory leak with CryptGetProvParam

    I suspect there is a memory leak in the function CryptGetProvParam. I made a Win32Console app in Visual Studio 2008 to recreate the problem. With the example app running it is possible to use Task Manager to see the memory usage of the .exe steadily increase
    over time.
    I called the app TestSecurityDescriptorWin32Console. Below I have pasted the contents of TestSecurityDescriptorWin32Console.cpp.
    I am looking to verify that the problem is with the CryptGetProvParam function, and if this is the case then to get the bug fixed.
    Thank you for any help
    // TestSecurityDescriptorWin32Console.cpp : Defines the entry point for the console application.
    #include "stdafx.h"
    #include <windows.h>
    HCRYPTPROV GetContext();
    void ModifyCryptProvSecurity(HCRYPTPROV hProv);
    int _tmain(int argc, _TCHAR* argv[])
    DWORD dwSDLen = 0;
    HCRYPTPROV hProv = GetContext();
    // get dwSDLen
    printf("First CryptGetProvParam: %d\n",CryptGetProvParam(hProv,PP_KEYSET_SEC_DESCR, NULL, &dwSDLen, DACL_SECURITY_INFORMATION));
    while (1) {
    BYTE* pbSD = (BYTE*)LocalAlloc(LHND,dwSDLen);
    PSECURITY_DESCRIPTOR
    pSD = (PSECURITY_DESCRIPTOR)pbSD;
    InitializeSecurityDescriptor(pSD,SECURITY_DESCRIPTOR_REVISION);
    // make pbSD size dwSDLen
    printf("Second CryptGetProvParam: %d\n",CryptGetProvParam(hProv,PP_KEYSET_SEC_DESCR, pbSD, &dwSDLen, DACL_SECURITY_INFORMATION));
    SECURITY_DESCRIPTOR*
    pSecurityDescriptor = (SECURITY_DESCRIPTOR*)pbSD;
    if (pSecurityDescriptor->Owner != NULL) FreeSid(pSecurityDescriptor->Owner);
    if (pSecurityDescriptor->Group != NULL) FreeSid(pSecurityDescriptor->Group);
    if (pSecurityDescriptor->Sacl != NULL) LocalFree(pSecurityDescriptor->Sacl);
    if (pSecurityDescriptor->Dacl != NULL) LocalFree(pSecurityDescriptor->Dacl);
    LocalFree(pbSD);
    Sleep(100);
    return 0;
    HCRYPTPROV GetContext()
    HCRYPTPROV hProv = NULL;
    HCRYPTKEY hKey = NULL;
        CHAR szPPName[100];
        DWORD dwPPNameLen = 100;
        CHAR szPPContainer[100];
        DWORD dwPPContainerLen = 100;
        // Attempt to acquire a handle to the default key container.
        if (CryptAcquireContext(
    &hProv,
    NULL,
    MS_DEF_PROV,
    PROV_RSA_FULL,
    CRYPT_MACHINE_KEYSET))
    printf("Opened default key container for crypto usage");
    else
    // Some sort of error occured...
    printf("(Allowable) Error acquiring default key container for crypto usage - ");
    // .. try to create default key container.
    if(CryptAcquireContext(
    &hProv,
    NULL,
    MS_DEF_PROV,
    PROV_RSA_FULL,
    CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET))
    printf("Created key container for crypto usage");
    else
    printf("Error Creating key container for crypto usage - ");
    return (NULL);
    // Get CSP name.
    if(CryptGetProvParam(
    hProv,
    PP_NAME,
    (BYTE *)szPPName,
    &dwPPNameLen,
    0))
    printf("Key CSP name is '%s'",szPPName);
    else
    // Error getting key container name.
    printf("Failed to retrieve CSP name - ");
    // Get name of key container.
    if(CryptGetProvParam(
    hProv,
    PP_CONTAINER,
    (BYTE *)szPPContainer,
    &dwPPContainerLen,
    0))
    printf("Key container provider name is '%s'",szPPContainer);
    else
    // Error getting key container name.
    printf("Failed to retrieve key container name - \n");
    return hProv;

    "BYTE* pbSD = (BYTE*)LocalAlloc(LHND,dwSDLen);"
    LHND? It's surprising that this doesn't crash the program. Use LPTR.
    More generally, stay away from LocalAlloc/LocalFree, use malloc/new/HeapAlloc. Use LocalAlloc only if the API you're working with specifically requires LocalAlloc, that's rare.

  • Memory Leak in my JDBC application.

    Hi
    I am experiencing a memory leak in a test application using the JDBC-ODBC bridge to access an MS Access DB.
    I close the result set, statement and connection objects after each query. Even then the memory allocated to the process increases by about 20K after each query.
    Is there anything else I should do apart from closing these objects??
    Thanks a lot for your time.
    Fred.

    I am having the same problem using JDBC-ODBC bridge with the MS SQL server DB. Even after closing all of the objects as specified.
    Sorry couldn't be of much help but check the following link
    http://www.allaire.com/Handlers/index.cfm?ID=12409&Method=Full
    But I do not have a work around for this may be I am not looking at the right response.
    Can some one please help.

  • Memory leak in AudioServicesCreateSystemSoundID with sound files

    hi !
    Instruments indicates a 64Ko memory leak in "AudioServicesCreateSystemSoundID" when I use a sound that I have created with GBand / iTunes. When I use the sound file "tap.aif" from the "sysSound" sample, there is no memory leak.
    What's wrong with my audio file ?
    It's a AIFF file, 95Ko, 8 bit mono 22Khz @ 176kbps.
    thanks...

    appFile = [ [ NSBundle mainBundle ] pathForResource : _filename ofType : _extension ];
    FileUrl = [ NSURL fileURLWithPath: appFile ];
    if ( AudioServicesCreateSystemSoundID( ( CFURLRef ) FileUrl, &soundID ) != kAudioServicesNoError )
    return false;
    I don't think the code is wrong because when I change the name of the sound in '_filename', there is no leak.
    I haven't found in the documentation the audio file properties ( 8/16 bits, ... ) supported by 'AudioServicesCreateSystemSoundID'.
    The code is for iPhone.

  • Memory Leak with cloneModelFromCastMember()?

    Hello Experts!
    I have been experiencing an apparent memory leak within
    Director 11 when
    using cloneModelFromCastMember().
    I was making the assumption that calling resetWorld() on a
    w3D member
    onBeginSprite() would garbage collect any models previously
    cloned into that
    when I previously ran the movie.
    However, if I repeatedly start and stop the movie Director
    Gobbles roughly
    10Mb more memory each time. The memory usage does not reduce
    upon calling
    resetWorld()
    A good way to replicate this is to use
    cloneModelFromCastMember() on a
    largeish model in a repeat with i = 1 to 50 loop on the on
    beginSprite
    handler.
    Start and stop the movie over and over to see Director's
    memory usage hike
    up.
    Anybody have any advice why this is happening? Do I need to
    explicitly
    delete all models cloned into a member on stopMovie????
    Cheers
    Richard Smith

    Hi Zzzorro,
    Thanks for the advice!
    Why does cloning from external w3D members help? Does it
    avoid the memory
    leak? It never used to happen on Director 8.5 so it has to be
    a new Version
    10 / 11 bug right?
    I need to import several weightmapped boned characters into a
    3D member, and
    due to export issues each character has to have it's own w3D
    file.
    So I have to perform cloning at runtime to build the world. I
    also need to
    clone these characters based on the level, so I can't use
    just one single 3D
    member for both these reasons.
    Thanks for any further ideas.
    Richard Smith
    "zzzorro" <[email protected]> wrote in
    message
    news:gd4sn2$2l8$[email protected]..
    > as a rule of thumb:
    > whenever possible avoid cloneModelFromCastMember in the
    first place.
    > It is highly unrecommended and the intel engineers
    always recommended to
    > use
    > loadFile() with an external w3d file, which is much
    better than having the
    > w3d
    > file in the castlib and using cmfcm.
    > each cmfm rebuilds the whole scene and takes a lot of
    time the bigger the
    > scene is.
    > apart from glitches like leaks, which you found right
    now and other
    > things.
    >
    > I work very much with sw3d and I barely have more than
    one shockwave3d
    > member
    > in any of my movies. in very rare cases I use 2 sw3d
    members. Other than
    > that I
    > use one member where I build and load everything into
    from external w3d
    > files
    > with loadFile(), which is much more appropriate. the
    only downside is that
    > I
    > can't change the model name, but there are ways to deal
    with it.
    >

  • I have a memory leak, objective-c 2.0, and garbage collector...

    the code i am using is a modification of the code/problem found in "Cocoa with Objective-C", chapter 3.
    i have tried to use the objective-c 2.0 garbage collector methodology, using @property, @synthesize, etc. when i run the code as listed below i get a leaking message.
    [Session started at 2008-02-01 23:33:37 -0500.]
    2008-02-01 23:33:38.070 SongsFoundationTool[28876:10b] * _NSAutoreleaseNoPool(): Object 0x2040 of class NSCFString autoreleased with no pool in place - just leaking
    Stack: (0x96b10178 0x96a3e0f8)
    2008-02-01 23:33:38.075 SongsFoundationTool[28876:10b] Song 1: We Have Exposive
    2008-02-01 23:33:38.076 SongsFoundationTool[28876:10b] * _NSAutoreleaseNoPool(): Object 0x2060 of class NSCFString autoreleased with no pool in place - just leaking
    Stack: (0x96b10178 0x96a3e0f8)
    2008-02-01 23:33:38.078 SongsFoundationTool[28876:10b] Song 2: Loops of Fury
    The Debugger has exited with status 0.
    when i include the commented out section, in the implementation file section, the description method, and use song1 and song2, in main, instead of song1.name and song2.name the program seems to run fine.
    The Debugger has exited with status 0.
    [Session started at 2008-02-01 23:38:24 -0500.]
    2008-02-01 23:38:24.375 SongsFoundationTool[28936:10b] Song 1: We Have Exposive
    2008-02-01 23:38:24.379 SongsFoundationTool[28936:10b] Song 2: Loops of Fury
    The Debugger has exited with status 0.
    please help me understand what's happening here.
    also, why was it necessary to use
    @property(copy, readwrite) NSString *name;
    @property(copy, readwrite) NSString *artist;
    instead of
    @property(readwrite) NSString *name;
    @property(readwrite) NSString *artist;
    thanks everyone, the code is below.
    // ....................... header file ...............
    #import <Cocoa/Cocoa.h>
    @interface Song : NSObject {
    NSString *name;
    NSString *artist;
    @property(copy, readwrite) NSString *name;
    @property(copy, readwrite) NSString *artist;
    @end
    //.................... the implementation file ..................
    #import "Song.h"
    @implementation Song
    @synthesize name;
    @synthesize artist;
    -(NSString *) description
    return [ self name ];
    @end
    //................................ main............................
    #import <Foundation/Foundation.h>
    #import "Song.h"
    int main (int argc, const char * argv[]) {
    Song *song1 = [ [ Song alloc ] init ];
    song1.name= @"We Have Exposive" ;
    [ song1 setArtist: @"The Future Sound Of Londown" ];
    Song *song2 = [ [ Song alloc ] init ];
    [ song2 setName: @"Loops of Fury" ];
    [ song2 setArtist: @"The Chemical Brothers" ];
    // Display Object
    NSLog( @"Song 1: %@", song1.name );
    NSLog( @"Song 2: %@", song2.name );
    // include statements below if -description method is uncommented
    // then comment out the two statements above. no memory leak if the code
    // is used from the statements below and - description is not commented out and
    // the two NSLog statements above are commented out.
    NSLog( @"Song 1: %@", song1 );
    NSLog( @"Song 2: %@", song2 );
    return 0;
    }

    Normally, your main only has a call to NSApplicationMain(). If you aren't doing a traditional MacOS X application, you will still want at least NSApplicationLoad() to get enough of the runtime to avoid those messages.
    I don't know for sure about the syntax of Objective-C 2.0. That stuff is all new. What error message are you getting that indicated that (copy, readwrite) is required? Could you provide a link to the actual example source? I did a quick check and assign and readwrite are the defaults. It is possible that readwrite by itself makes no sense. But I'm just guessing.

Maybe you are looking for