Applescript using XCODE 3.1.1 memory leak?

Does anyone know about a memory leak in applescript applications. I've written an application which displays images. It appears to retain each displayed image in memory untill it finally hangs. Does anybody know if this is new in 3.1.1 as I don't remember it happening with 3.0.0 ?
If anybody knows how to release it please let me know.
Thanks JS.

Take a look at the discussion section and sample code below it in the docs for the "load image" command in the AppleScript Studio Terminology Reference. Loaded images are indeed retained, but supposedly can be deleted when you're done with them.
This doesn't appear to be new in Xcode 3.1.1 though.
Steve

Similar Messages

  • Applescript Image Events appears to have memory leak (or I don't know what I am doing)

    Using Image Events to create images and thumbnails for a website. The following code results in very large memory leaks in Image Event process. I have documented results of test runs in the comments.
    The leak (or poor coding on my part) results in a total system halt if I attempt to process more than about 400 images at a time. Basically, I run out ot physical memory. I am running a new model 13" MBP with 8GM RAM.  I have to manually stop Image Events to reclaim the memory (or reboot of course).
    Any help/suggestions would be appreciated.
    (* test memory leak in Image Events *)
              tests with 58 photos selected in iPhoto
              5.7 MB left in Image Events after run with only open and close
              22.0 MB left in Image Events after run with open, save and close
              45.9 MB left in Image Events after run with open, scale, save and close
              A run with 382 photos selected used OVER 3.8 GB (gigabytes) and the
              mac ran out of physical memory so I had to stop the test.
    tell application "Finder"
              set imageFolder to folder "test" of home as alias
    end tell
    tell application "iPhoto"
              set currPhotoList to the selection
              repeat with currPhoto in currPhotoList
                        log name of currPhoto as string
                        set theImagePath to image path of currPhoto
                        tell application "Image Events"
      launch
                                  set theImage to open theImagePath
      scale theImage to size 128
      save theImage in imageFolder as JPEG with icon
      close theImage
                        end tell
              end repeat
    end tell
    --- end of code example

    Does the following code do any difference? Most likely no I guess… but better try than nothing.
    tell application "Finder"
        set imageFolder to folder "test" of home as text -- instead of “as alias” (see theTargetPath below)
    end tell
    set theImagePaths to {}
    set theImagePathsRef to a reference to theImagePaths -- faster with big lists
    tell application "iPhoto"
        set currPhotoList to the selection
        repeat with currPhoto in currPhotoList
            log name of currPhoto as string
            get POSIX file (image path of currPhoto) as alias -- faster ?
            copy result to the end of theImagePathsRef
        end repeat
    end tell
    tell application "Image Events"
        launch
        repeat with theImagePath in theImagePaths
            set theImage to open theImagePath
            scale theImage to size 128
            set theTargetPath to (imageFolder & name of theImagePath)
            save theImage in theTargetPath as JPEG with icon
            close theImage
        end repeat
    end tell

  • I seem to have what used to be called a memory leak and need to restart FF every 45 minutes or so - can I fix it?

    2fter about 2 weeks of closely monitoring 2 PC's with roughly the same specs running the same Facebook game it has become clear that as minutes go by the amount of memory being consumed by Firefox goes up. It starts at about 250 megs and runs up to about 1 gig in ~45 minutes. Both machines are 3 ghz, 3gb machines running 32 bit XP home. (Older P4 CPU's) One of the machines is running DDR2 and the other DDR
    When the memory get's to about 750 megs used by FF the entire system bogs down noticeably and gets almost unusable beyond that. Is there something I can do about it or is there a way for me to automate the shut down and restart of FF and have it return to the game?

    A tiny suggestion,
    I heard that a lot of the time this is caused by extensions and add-ons. Try to disable all of them and see if it is any difference. If its better just enable one extension at the time until you found the problem.
    If you cant solve the memory issue, here is a fix that should work making ff restart, if not at a specific memory usage, but on a specific time at least:
    Open notepad and write the following:
    ''taskkill /f firefox.exe''
    Name it FFShutdown.bat and save it
    Open a new page of notepad with this line:
    start firefox.exe https://support.mozilla.com/
    Save that file as FFstart.bat
    Now go to windows task scheduler
    Start > Programs > Accessories > System Tools > Scheduled Tasks
    Browse to your FFShutdown.bat and choose daily and set a time.
    Do the same for FFStart.bat but set it one minute later.
    Repeat this if you want it happen more than once per day.
    Hope that helps

  • 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

  • Memory Leak using CertOpenStore on Windows 2008 R2

    I have a program (runs both 32 and 64 bit ) that when using CertOpenStore results in a memory leak on Windows 2008 R2 only (I haven't tried 2012, but this code has run for years on 2000, 2003, 2008 without issues)
    Sample code to reproduce the issue:
    int main( int argc, char** argv )
    HCERTSTORE store;
    int go = 1;
    while( go ){
    store = CertOpenStore(
    CERT_STORE_PROV_SYSTEM_A,
    0,
    0,
    CERT_SYSTEM_STORE_LOCAL_MACHINE | CERT_STORE_OPEN_EXISTING_FLAG,
    "MY" );
    if( store ){
    //if( !CertCloseStore( store , CERT_CLOSE_STORE_CHECK_FLAG ) ){
    if( !CertCloseStore( store , CERT_CLOSE_STORE_FORCE_FLAG ) ){
    if( GetLastError() == CRYPT_E_PENDING_CLOSE ){
    printf( "!" );
    else{
    go = 0;
    else{
    go = 0;
    Sleep( 10 );
    return 0;
    The callstack for allocations pretty much are all like this  (this is from a 32 bit process on a 2008R2 box)
          HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
            02e75af0 000f 0000  [00]   02e75b08    0005e - (busy)
            7724dff2 ntdll!RtlAllocateHeap+0x00000274
            745f6017 AcLayers!malloc+0x00000079
            7460dc96 AcLayers!NS_VirtualRegistry::MakePath+0x00000056
            7460e817 AcLayers!NS_VirtualRegistry::CVirtualRegistry::OpenKeyW+0x000000a9
            7460f21a AcLayers!NS_VirtualRegistry::APIHook_RegOpenKeyExW+0x00000036
            743d2641 AcGenral!NS_WRPMitigation::APIHook_RegOpenKeyExW+0x00000024
            7527a246 crypt32!RegOpenHKCUKeyExU+0x00000055
            7527de26 crypt32!OpenSubKeyEx+0x00000108
            7527e4d8 crypt32!OpenSubKey+0x00000015
            7527ed88 crypt32!OpenSystemRegPathKey+0x00000033
            75281a2f crypt32!EnumPhysicalStore+0x00000162
            75281d0e crypt32!I_CertDllOpenSystemStoreProvW+0x0000015c
            752c9fce crypt32!I_CertDllOpenSystemStoreProvA+0x0000006c
            7527e49a crypt32!CertOpenStore+0x0000010e
    Anyone have any ideas of a hotfix available for this?
    thanks

    Might ask them here about this.
    Windows Desktop Dev forums on MSDN
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • Memory leaks in MFC while using CDatabase::OpenEx()

    Hi,
    This question has been asked previously but the explanation was not in detail and i could never reach to the bottom of it.
    I hope i can elaborate more on the problem statement and i can get a resolution/explanation from the experts here.
    Consider the following two sample codes;
    1.
    int count = 200;
    for (int i=0; i <count; ++i)
    try
    CDatabase *db = new CDatabase;
    BOOL bRes = db->OpenEx(_T("DSN=MyData;UID=anon;PWD=pass"));
    db->Close();
    delete db;
    db=NULL;
    catch (CDBException* e)
    e->Delete();
    2.
    CDatabase *db = new CDatabase;
    int count = 200;
    for (int i=0; i <count; ++i)
    try
    BOOL bRes = db->OpenEx(_T("DSN=MyData;UID=anon;PWD=pass"));
    db->Close();
    catch (CDBException* e)
    e->Delete();
    delete db;
    db=NULL;
    return 0;
    delete db;
    db=NULL;
    The first sample code leaks a lot of memory and it can be easily observed from the task manager, the memory usage keeps on growing.
    The second sample code does not leak any memory if i observe the memory usage from the task manager.
    To find out the cause of the memory leak i ran the code through rational purify, both the codes are leaking memory according to rational purify. The first code leaks significantly more memory than the second one. The DLL pointed by rational purify are MFC
    DLLs (inserting the screen shot below)
    Is this a known issue with the MFC DLL or am i doing something wrong?
    I have a server application where i have to create CDatabase object multiple times and i end up leaking a lot of memory over a period of time.
    I can provide more information about this issue if required. Thanks in advance.

    I am trying to reproduce this issue on my side, but it seem there is no memory leak in my simple sample. I use _CrtDumpMemoryLeaks() to test the memory leak.
    https://msdn.microsoft.com/en-us/library/d41t22sb.aspx
    If I comment this line: db->Close();
    I can detect the memory leak at CDatabase
    *db =
    new CDatabase; 
    See the screenshot.
    If follow your sample code, there is memory leak message in the output view pane.
    #define CRTDBG_MAP_ALLOC
    #include <stdlib.h>
    #include <crtdbg.h>
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif.....int CMFCCdbMLTestApp::ExitInstance()
    // TODO: Add your specialized code here and/or call the base class
    _CrtDumpMemoryLeaks();
    return CWinApp::ExitInstance();
    May you can use some use tool like WinDbg tool to find more information about this issue. 
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Memory Leak when just launched and Idle..  fixes when being used ??  [HELP]

    So I'm in the debugging and testing phase of my app and using this tool for tracking memory leaks ( https://github.com/mrdoob/Hi-ReS-Stats )
    When I launch my app my numbers are
    FPS: 61/60
    MS: 17
    MEM: 3.157
    MAX: 3.157
    Now immediately my memory starts increasing    from  3.157, 3.167, 3.177, 3.187, 3.197 and so on.
    Now if I make any nav selection in my app
    MEM changes back down to about 3.215
    but then it starts its count again   3.215, 3.225,  3.235, 3.445, 3.455
    I don't have any loops happening.
    Has anyone run in to this ?
    I'm almost tempted to force garbage collection every 60 seconds that the app is idle or something.  Not the best way to handle this ..   I just dont know where the leak is happening.
    Any support is appreciated!
    Cheers!

    Hi there - I just had the same query a couple of days ago (http://forums.adobe.com/thread/977174?tstart=30).
    I saw the same symptoms on my app so I built a blank app with just the profiler on stage. I've been monitoring it for a few days now and notice that memory does creep up even when the app is left idle (apart from the profiler) - but ... and this is the important bit ... it does periodically get reduced back to the starting point (when the garbage collector kicks in and memory is released).
    When I was monitoring my app the time through this cycle could be well over 5 mins.
    If you actually use the monitor when putting your app through it's paces you'll see memory being gobbled up more rapidly and hopefully (if you've no leaks) the garbage collection kicking in more regularly and bringing the reported usage back down.

  • 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 

  • Memory Leak in .swf

    Memory Leak issue with CS4
    Using CS4, we have a memory leak and I can not find the
    source of the problem.
    http://tiny.cc/O7D3e here is the
    link to the testing site. If you take a look at your task manager
    you will see it your RAM will continue to increase even after two
    or three cycles. It does not stabilize.
    We are using FlashEff | Flash Effects Component in order to
    generate the smooth transitions. However, I have done some
    debugging and even completely deleted the plug n from the file and
    it still continually leaks memory. Does anyone have any possible
    solutions or causes for this.

    One idea - there is a separate stack of memory in the flash
    player where loaded classes in separate application domains exist,
    and these classes are not being garbage collected....however, there
    is a line in adobe's documentation here:
    http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Liv eDocs_Parts&file=00000327.html
    under "Usage C" :
    quote:
    Having a new application domain also allows you to unload all
    the class definitions for garbage collection, if you can ensure
    that you do not continue to have references to the child SWF.
    Given that, as far as I can see from this code, there is no
    reference to the loaded .swf maintained....it seems to me like the
    loaded data (graphical assets AND classes) should be garbage
    collected - but, while you WILL see a slight drop in memory after
    the removal of the SWF, the overall memory continues to increase
    the more you do it. Could Adobe be mistaken?

  • FIrefox betrayed by its own "developers"? Memory Leak Work Around at Bottom

    Firefox SUCKS memory and holds onto it. Try this test: Open it, leave ONE tab, open and sit back and and watch the damn thing crash.
    Funny, as soon as the project people started getting so much money from Google that they had to restructure to avoid losing its non-profit status Firefox developed an insatiable thirst for RAM that has only gotten worse in the YEARS since. They won't fix the problem, they won't acknowledge the problem, the ignore every post about it . . . . So, is killing FF's user base the price for the continued Google money that they so quickly whored themselves out for? Has FF been run by Google these last few years? They certainly couldn't wreck any better.
    Posted by Wahoo at https://support.mozilla.org/en-US/questions/939920
    "Using ADD-ons to remove memory leak. Mozilla says to remove add-ons to fix leak. Firefox sucks memory. it always has and always will. Nobody wants to admit it exsists on the Mozilla side must less fix it. Firewalls , etc do not cause the leak. You can remove all your ad-ons and leave firefox open and it will suck memory. Every tab you open drains your memory and continues to climb without opening any more. You can then close all your tabs and Firefox will not release the memory. Just fix it guys, it cant be that difficult "
    Posteby Onmicide at https://support.mozilla.org/en-US/questions/939920
    "There is a way to stay on top of the memory usage:
    Go to about:memory and scroll to the bottom. There are buttons there for garbage collection and minimizing memory usage. "

    Please try this two minute test.
    '''Create a new Firefox profile'''
    A new profile will have your system-installed plugins (e.g., Flash) and extensions (e.g., security suite toolbars), but no themes, other extensions, or other customizations. It also should have completely fresh settings databases and a fresh cache folder.
    Exit Firefox and start up in the Profile Manager using Start > search box (or Run):
    firefox.exe -P
    Any time you want to switch profiles, exit Firefox and return to this dialog.
    You'll click the Create Profile button. I recommend using the default location suggested, and to avoid data loss, not re-using any existing folder. Then start Firefox in the new profile you created.
    What happens with memory usage with the two default tabs open, or another tab of your choice?
    When returning to the Profile Manager, you might be tempted to use the Delete Profile button. But... it's a bit too easy to accidentally delete your "real" profile, so I recommend resisting the temptation. If you do want to clean up later, I suggest making a backup of all your profiles first in case something were to go wrong.

  • RMI memory leak

    My program use RMI, and I remark memory leak, then I tried RMI sample from jbuilder6, I modified this sample, to send 1Mb file via RMI.
    I write how much RAM are used
    before 168 mb
    rmiregistry 172Mb used 8 Mb
    RMIserver 189Mb 18 Mb
    RMIclient up to 227Mb 38Mb
    end when RMIclient exit 212Mb where is 23 Mb??? 212-189 ????
    This is my changes, and all program are after that:
    public String getDate() {
    System.out.println("SimpleRMIImpl.getDate()");
    String s=null;
    try {
    InputStream fileIn = new FileInputStream("Readme.txt2");
    byte buff[] = new byte[fileIn.available()];
    int i = fileIn.read(buff);
    s = new String(buff);
    } catch(FileNotFoundException e) {
    e.printStackTrace();
    } catch(IOException e) {
    e.printStackTrace();
    return new String(s);
    All program:
    package com.borland.samples.rmi;
    import java.rmi.*;
    import java.rmi.registry.*;
    import java.rmi.server.*;
    import java.util.Date;
    public class SimpleRMIClient
    public static void main(String[] argv) {
    String serverName = "";
    System.setSecurityManager(new RMISecurityManager());
    if (argv.length != 1) {
    try {
    serverName = java.net.InetAddress.getLocalHost().getHostName();
    catch(Exception e) {
    e.printStackTrace();
    else {
    serverName = argv[0];
    if (serverName == "") {
    System.out.println("usage: java SimpleRMIClient <IP address of host running RMI server>");
    System.exit(0);
    try {
    //bind server object to object in client
    SimpleRMIInterface myServerObject = (SimpleRMIInterface) Naming.lookup("//"+serverName+"/SimpleRMIImpl instance");
    //invoke method on server object
    String d = myServerObject.getDate();
    System.out.println("Date on server is " + d);
    catch(Exception e) {
    System.out.println("Exception occured: " + e);
    System.exit(0);
    System.out.println("RMI connection successful");
    package com.borland.samples.rmi;
    import java.rmi.*;
    import java.rmi.server.UnicastRemoteObject;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.FileInputStream;
    public class SimpleRMIImpl extends UnicastRemoteObject implements SimpleRMIInterface
    public SimpleRMIImpl(String name) throws RemoteException {
    super();
    try {
    Naming.rebind(name, this);
    catch (Exception e) {
    if (e instanceof RemoteException)
    throw (RemoteException)e;
    else
    throw new RemoteException(e.getMessage());
    public String getDate() {
    System.out.println("SimpleRMIImpl.getDate()");
    String s=null;
    try {
    InputStream fileIn = new FileInputStream("Readme.txt2");
    byte buff[] = new byte[fileIn.available()];
    int i = fileIn.read(buff);
    s = new String(buff);
    } catch(FileNotFoundException e) {
    e.printStackTrace();
    } catch(IOException e) {
    e.printStackTrace();
    return new String(s);
    package com.borland.samples.rmi;
    public interface SimpleRMIInterface extends java.rmi.Remote
    public String getDate() throws java.rmi.RemoteException;
    package com.borland.samples.rmi;
    import java.rmi.*;
    import java.rmi.server.UnicastRemoteObject;
    public class SimpleRMIServer
    public static void main(String[] argv) {
    System.setSecurityManager(new RMISecurityManager());
    try {
    SimpleRMIImpl implementation = new SimpleRMIImpl("SimpleRMIImpl instance");
    System.out.println("SimpleRMIImpl ready");
    catch (Exception e) {
    System.out.println("Exception occurred: " + e);
    Can you explain why this program use so much memory?
    Valdas

    Memory Usage and its distribution are done by the JVM....u cannot posibly account for each Mega bit of memory while it is used. Also, the File Copying Operation Involves JVM interacting with the OS which in turn interacts with the peripeherals such as ur harddisk, which are comparetively slower then the Processor speed. So the bottom line is ur same program will work at different RAM levels in diff machines with diff hardwares......If u system is indeed working too much then u can check out and sut down many services that u might have otherwise started...posiiblity of a Virus should not be ruled out either.....and the code itself is no problem at all although u might increase a bit by using some FIleReader, BufferredReader/Writer and other faster Streams.
    Hope it helps,
    Cheers,
    Manja

  • Memory leak in Real-Time caused by VISA Read and Timed Loop data nodes? Doesn't make sense.

    Working with LV 8.2.1 real-time to develop a host of applications that monitor or emulate computers on RS-422 busses.   The following screen shots were taken from an application that monitors a 200Hz transmission.  After a few hours, the PXI station would crash with an awesome array of angry messages...most implying something about a loss of memory.  After much hair pulling and passing of the buck, my associate was able to discover while watching the available memory on the controller that memory loss was occurring with every loop containing a VISA read and error propogation using the data nodes (see Memory Leak.jpg).  He found that if he switched the error propogation to regular old-fashioned shift registers, then the available memory was rock-solid.  (a la No Memory Leak.jpg)
    Any ideas what could be causing this?  Do you see any problems with the way we code these sorts of loops?  We are always attempting to optimize the way we use memory on our time-critical applications and VISA reads and DAQmx Reads give us the most heartache as we are never able to preallocate memory for these VIs.  Any tips?
    Dan Marlow
    GDLS
    Solved!
    Go to Solution.
    Attachments:
    Memory Leak.JPG ‏136 KB
    No Memory Leak.JPG ‏137 KB

    Hi thisisnotadream,
    This problem has been reported, and you seem to be exactly reproducing the conditions required to see this problem. This was reported to R&D (# 134314) for further investigation. There are multiple possible workarounds, one of which is the one that you have already found of wiring the error directly into the loop. Other situations that result in no memory leak are:
    1.  If the bytes at port property node is not there and a read just happens in every iteration and resulting timeouts are ignored.
    2.  If the case structure is gone and just blindly check the bytes at port and read every iteration.
    3.  If the Timed Loop is turned into a While loop.
    Thanks for the feedback!
    Regards,Stephen S.
    National Instruments
    Applications Engineering

  • 1.3 memory leak?

    Hi all, I set my LR 1.3 on Vista to create all standard thumbnails on about 20,000 images, and when I came back it was using 700MB memory, and as it was going I saw memory use increase. When I quit and restarted LR was using 190MB. Maybe a memory leak somewhere?
    Regards,
    Cor

    Hi Jeff, it is the fact that I do actually have a grasp of how system allocation, memory management and resource management works that I, without any evil plot to make LR seem bad, tried to point out what could possibly be a problem. If it isn't then im glad, and no need to make me need to put on my flame resistant suit.
    When I see an application doing 1 thing in a loop, in this case creating previews, and at every iteration of that loop use more memory, I thought id ask if thats supposed to happen. In many applications that is a big hint towards a memory leak. Granted, like Matteo I have zero experience in the windows environment, but im pretty fluent in several programming languages on unix systems. Things probably work a lot different there.
    I immediately believe you when you say thats not the case here, but as a techie im interested nonetheless. What's it adding to memory every loop iteration? A memory footprint of 700MB doesnt phase me one bit, I was merely triggered by the slow increase of it after every conversion.
    Regards,
    Cor

  • NewDirectByteBuffer memory leak

    I ve coded a new JNI program , when i try to use NewDirectByteBuffer function ,
    i get memory leak on my program , when i cancel NewDirectByteBuffer function call everything is going ok after that i ve added DeleteLocalRef function may stop memory leak but its not...Whats the problem can be ? Is it a bug ?
    I'm using Java 6 SDK AMD64bit edition
    static JNIEnv *pEnv = NULL;
    g_pVM->AttachCurrentThread( (VOID**)&pEnv,NULL );
    jobject objectByteBuffer = pEnv->NewDirectByteBuffer(pBuffer,lBufferSize);
    pEnv->CallVoidMethod(g_ObjListener,g_methodID,objectByteBuffer);
                   pEnv->DeleteLocalRef(objectByteBuffer);

    I want to build a library and pass that ByteBuffer to external users'If it was me I would try to get rid of that requirement. But otherwise....
    Finalize would be required but only as a fail safe. You should not document that you have such a fail safe. Rather you should document that the users must correctly call a cleanup method when they are through. And document it in such a way to make it obvious how it must work with exceptions as well.
    If this really is a library, where you are unlikely to be able to assist the users, then you might want to provide an optional way to track how many buffers have been allocated and cleaned. Thus the users will have a primitive way to validate correct clean up.

  • Memory leak using xslprocessor.valueof in 11.1.0.6.0 - 64bit ??

    My company has made the decision to do all of our internal inter-system communication using XML. Often we may need to transfer thousands of records from one system to another and due to this (and the 32K limit in prior versions) we're implementing it in 11g. Currently we have Oracle 11g Enterprise Edition Release 11.1.0.6.0 on 64 bit Linux.
    This is a completely network/memory setup - the XML data comes in using UTL_HTTP and is stored in a CLOB in memory and then converted to a DOMDocument variable and finally the relevant data is extracted using xslprocessor.valueof calls.
    While this is working fine for smaller datasets, I've discovered that repeated calls with very large documents cause the xslprocessor to run out of memory with the following message:
    ERROR at line 1:
    ORA-04030: out of process memory when trying to allocate 21256 bytes
    (qmxdContextEnc,)
    ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 1010
    ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 1036
    ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 1044
    ORA-06512: at "SCOTT.UTL_INTERFACE_PKG", line 206
    ORA-06512: at line 28
    Elapsed: 00:03:32.45
    SQL>
    From further testing, it appears that the failure occurs after approximately 161,500 calls to xslprocessor.valueof however I'm sure this is dependent on the amount of server memory available (6 GB in my case).
    I expect that we will try and log a TAR on this, but my DBA is on vacation right now. Has anyone else tried calling the xslprocessor 200,000 times in a single session?
    I've tried to make my test code as simple as possible in order to track down the problem. This first block simply iterates through all of our offices asking for all of the employees at that office (there are 140 offices in the table).
    DECLARE
    CURSOR c_offices IS
    SELECT office_id
    FROM offices
    ORDER BY office_id;
    r_offices C_OFFICES%ROWTYPE;
    BEGIN
    OPEN c_offices;
    LOOP
    FETCH c_offices INTO r_offices;
    EXIT WHEN c_offices%NOTFOUND;
    utl_interface_pkg.get_employees(r_offices.office_id);
    END LOOP;
    CLOSE c_offices;
    END;
    Normally I'd be returning a collection of result data from this procedure, however I'm trying to make things as simple as possible and make sure I'm not causing the memory leak myself.
    Below is what makes the SOAP calls (using the widely circulated UTL_SOAP_API) to get our data and then extracts the relevant parts. Each office (call) should return between 200 and 1200 employee records.
    PROCEDURE get_employees (p_office_id IN VARCHAR2)
    l_request utl_soap_api.t_request;
    l_response utl_soap_api.t_response;
    l_data_clob CLOB;
    l_xml_namespace VARCHAR2(100) := 'xmlns="' || G_XMLNS_PREFIX || 'EMP.wsGetEmployees"';
    l_xml_doc xmldom.DOMDocument;
    l_node_list xmldom.DOMNodeList;
    l_node xmldom.DOMNode;
    parser xmlparser.Parser;
    l_emp_id NUMBER;
    l_emp_first_name VARCHAR2(100);
    l_emp_last_name VARCHAR2(100);
    BEGIN
    --Set our authentication information.
    utl_soap_api.set_proxy_authentication(p_username => G_AUTH_USER, p_password => G_AUTH_PASS);
    l_request := utl_soap_api.new_request(p_method => 'wsGetEmployees',
    p_namespace => l_xml_namespace);
    utl_soap_api.add_parameter(p_request => l_request,
    p_name => 'officeId',
    p_type => 'xsd:string',
    p_value => p_office_id);
    l_response := utl_soap_api.invoke(p_request => l_request,
    p_url => G_SOAP_URL,
    p_action => 'wsGetEmployees');
    dbms_lob.createtemporary(l_data_clob, cache=>FALSE);
    l_data_clob := utl_soap_api.get_return_clob_value(p_response => l_response,
    p_name => '*',
    p_namespace => l_xml_namespace);
    l_data_clob := DBMS_XMLGEN.CONVERT(l_data_clob, 1); --Storing in CLOB converted symbols (<">) into escaped values (&lt;, &qt;, &gt;).  We need to CONVERT them back.
    parser := xmlparser.newParser;
    xmlparser.parseClob(parser, l_data_clob);
    dbms_lob.freetemporary(l_data_clob);
    l_xml_doc := xmlparser.getDocument(parser);
    xmlparser.freeparser(parser);
    l_node_list := xslprocessor.selectNodes(xmldom.makeNode(l_xml_doc),'/employees/employee');
    FOR i_emp IN 0 .. (xmldom.getLength(l_node_list) - 1)
    LOOP
    l_node := xmldom.item(l_node_list, i_emp);
    l_emp_id := dbms_xslprocessor.valueOf(l_node, 'EMPLOYEEID');
    l_emp_first_name := dbms_xslprocessor.valueOf(l_node, 'FIRSTNAME');
    l_emp_last_name := dbms_xslprocessor.valueOf(l_node, 'LASTNAME');
    END LOOP;
    xmldom.freeDocument(l_xml_doc);
    END get_employees;
    All of this works just fine for smaller result sets, or fewer iterations (only the first two or three offices). Even up to the point of failure the data is being extracted correctly - it just eventually runs out of memory. Is there any way to free up the xslprocessor? I've even tried issuing DBMS_SESSION.FREE_UNUSED_USER_MEMORY but it makes no difference.

    Replying to both of you -
    Line 206 is the first call to xslprocessor.valueof:
    LINE TEXT
    206 l_emp_id := dbms_xslprocessor.valueOf(l_node, 'EMPLOYEEID');
    This is one function inside of a larger package (the UTL_INTERFACE_PKG). The package is just a grouping of these functions - one for each type of SOAP interface we're using. None of the others exhibited this problem, but then none of them return anywhere near this much data either.
    Here is the contents of V$TEMPORARY_LOBS immediately after the crash:
    SID CACHE_LOBS NOCACHE_LOBS ABSTRACT_LOBS
    132 0 0 0
    148 19 1 0
    SID 132 is a SYS session and SID 148 is mine.
    I've discovered with further testing that if I comment out all of the xslprocessor.valueof calls except for the first one the code will complete successfully. It executes the valueof call 99,463 times. If I then uncomment one of those additional calls, we double the number of executions to a theoretical 198,926 (which is greater than the 161,500 point where it usually crashes) and it runs out of memory again.

Maybe you are looking for

  • A very strange issue with my Ipod Classic

    Hello everyone Well I have a Ipod Classic 160gb all this time I was using it and was so flawlessly, but 4 days ago, suddenly when I connect the Ipod into Itunes and listened some songs for a while, I go to the Ipod in the windows explorer, open it an

  • QR code date merge error.

    When trying to create a qr code data merge in indesign, I cannot seem to create actual QR codes. Instead they are previewing as text. How can I create a QR data merge code with QR codes?

  • Unable to create a new library jxl-2.6 in 9ijdeveloper.issue is critical,

    Hi team, Please provide the steps to create new library jxl-2.6 in OAF 9ijdeveloper standalone system, 1)where import the jxl-2.6.jar file. 2) what paths should be provide for source,class and doc in stand alone 9i jdeveloper. Thanks in advance, Rega

  • FINAL STEP BEFORE MAKING DVD

    I have iMovie '09. I've downloaded my project into the DVD format. I want to put the last title on this project using the "rotating drum" which holds both copy and photos. I'm not sure how to get the copy inserted nor the photos. Thanks for any help

  • Long Distance Storage Replication

    Looking for some data on storage replication between data centers connected via VPN. VPN is based on 7206VXR/IOS w/ DS-3 access. DS3 endpoints are the same Tier1 provider. Distance is Miami to/from Chicago. Replication fo 20Gb SQL Database (initially