Memory leak when transferring pdf...help needed

Dear All,
I'm a newbie in developing java app. I'm making a web based application in reporting using JSP. java 1.6.02, jasper report 204, i-report 2.0.0
Client : OS : Win xp, memory 512MB
Server : Tomcat 6.0
DB Server : SQL Server 2005
OS Server : Windows Server 2003, memory 1GB
Report spec : .pdf based, with up to 1million record
Here's the code :
String query;
        try {
        String filereport = request.getRealPath("division/accounting/template/POReport.jrxml");
        InputStream input = new FileInputStream(filereport);
        Class.forName(odbcDriver);
        Connection conn = DriverManager.getConnection(odbcURL,username,passwd);
        ResultSet rset = null;
        CallableStatement cs = null;
        query = "{ call sp_tpo_list }";
          cs = conn.prepareCall(query);
          rset = cs.executeQuery();
        JRDataSource dataSource = new JRResultSetDataSource(rset);
        JasperDesign design = JRXmlLoader.load(input);
        JasperReport report = JasperCompileManager.compileReport(design);
        JasperPrint print = JasperFillManager.fillReport(report, null, dataSource);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JasperExportManager.exportReportToPdfStream(print, baos);
        response.setContentType("application/pdf");
        response.setContentLength(baos.size());
        ServletOutputStream sos;
        sos = response.getOutputStream();
        baos.writeTo(sos);
        sos.flush();
        rset.close();
        cs.close();
        conn.close();
        sos.close();
        baos.close();
        input.close();      
        catch (FileNotFoundException fe) {}
        catch (JRException jre) {}
        catch (ClassNotFoundException cnfe) {}
        catch (SQLException sqle) {} 
        catch (IOException ioe) {}I've already increase heap memory in Tomcat Manager -Xms 64Mb -Xmx 512Mb.
But when i test with 1million record, out of heap memory error is coming out.
When i test with 500.000 record, it work out, but only when 1 client access. More than 1 client, out of heap memory error generated by the system.
How can this happen? How can i detect memory leaks occured in the program?
And pls let me know if you see something is missing in the code above.
Thank you

I dont think you have a memory leak. I think the problem is the xml file is 1000000 records long and takes up too much memory. Even if you find a way to increase memory size, you are loading down the server too much for other people's applications to run. I suggest instead reading up on xml and learning how to read in only a few records at a time, processing it, and getting the next set of records to process. There are two methods to parse an xml file using an xml parser, one is to parse it all and put it in memory, the other is to process one record at a time (an xml book explains it better).
However, I question why you have reports that are 1000000 records long. end-users cannot effectively use such records (you cant scroll through 1000000 records). I suggest finding a way to greatly decrease the number of records in each file such as by providing just the records a particular user needs to do his job and not all records. For instance, put a textfield on his screen to let him only fetch records within a certain date range.
Lastly, I suggest putting your code in a try/catch/finally block where the finally block actually closes the objects. Example:
finally{
if(conn!=null)
conn.close();
}

Similar Messages

  • Memory leak when transferring files Lion

    hi all, help   I'm experiencing a memory leak since upgrading to Lion when transferring shared files between my macbook pro and imac. This occures through ethernet (wireless/wired) and firewire 800. No other apps are open except activity montior and finder. I am trying to transfer about 100g of itunes music / video files and pictures. Time machine backups to my TC do not have this affect.
    When transfer starts the free memory slowly decreases whilst the inactive memory increases. Eventually the free memory drops below 10mg, active memory is approx 5-6gb and wired/active is about 2gb. Bascially as the free memory decreases the inactive memory increases however does not get realocated so the mac grinds to a halt and dies with lots of page outs etc.
    this only happens when trying to transfer files. I have tried whole folders and just small individual ones and noticed the same event. I am struggling to find the cuase of the problem - any ideas?
    mac os x 10.7.1
    processor 2.53 GHz Intel Core i5
    Memory 8 GB 1067 MHz DDR3
    cheers, Kevin

    I dont think you have a memory leak. I think the problem is the xml file is 1000000 records long and takes up too much memory. Even if you find a way to increase memory size, you are loading down the server too much for other people's applications to run. I suggest instead reading up on xml and learning how to read in only a few records at a time, processing it, and getting the next set of records to process. There are two methods to parse an xml file using an xml parser, one is to parse it all and put it in memory, the other is to process one record at a time (an xml book explains it better).
    However, I question why you have reports that are 1000000 records long. end-users cannot effectively use such records (you cant scroll through 1000000 records). I suggest finding a way to greatly decrease the number of records in each file such as by providing just the records a particular user needs to do his job and not all records. For instance, put a textfield on his screen to let him only fetch records within a certain date range.
    Lastly, I suggest putting your code in a try/catch/finally block where the finally block actually closes the objects. Example:
    finally{
    if(conn!=null)
    conn.close();
    }

  • Huge memory leak when closing PDF from Hyperlink

    I was wondering if anyone else has experienced this issue with Adobe Reader 11.0.10 on Windows 7 64bit:
    1. I have a list of hyperlinks in an Access Table to certain PDF files on a local network folder.
    2. Clicking the hyperlink opens the corresponding PDF.
    The PDF file opens just fine, and renders normally. The issue is when I attempt to close the PDF. This results in an instant Memory leak that will grow to 4GB in under 10 seconds. System crashes completely. I can reproduce the crash in Safe Mode as well. I am able to open/close the PDF from its source location normally without incident. Clean Uninstall/Reinstall produces the same results.
    Downgrade to Adobe 10 fixes the problem completely. I can reproduce the problem on all computers on my network (all running windows 7 32bit or 64bit) by upgrading to Reader 11.0.10.
    I prefer to keep my software updated to prevent vulnerabilities, so any help would be appreciated.

    That is very strange because it is a 32-bit program and cannot (according to popular wisdom) grow over 2 GB. Also, if it were to reach 2 GB it would simply crash, not break the system.
    Do you have a screen shot showing the 4 GB? There might be clues there what is happening.

  • Memory Leak when running Contacts

    I am having a big memory leak when running the app Contacts on a MB Air. It gobbles up 2 GB of ram in just a few minutes forcing a reboot. I have re-installed Mountain Lion 10.8.2 and it still leaks memory. Watching Activity Monitor shows the rapid increase in Ram being gobbled up by Contacts. Used Mackeeper to clear cache as well as ran Cocktail, all to no avail. Any tips would be greatly appreciated.

    The size of oracle.exe is not an indication of how the Java VM GC works; so you are not comparing apples to apples. It'll be too long to explain here but in my upcoming book (see hereafter), I gave a detailled explanation of the various memory areas the Java VM uses and how these are GCed and also how you can meausre their size (not all, though).
    In short you want to use OracleRuntime methods such as
    OracleRuntime.getSessionSize(); --> get he current size of Sessionspace
    OracleRuntime.getNewspaceSize(); --> get he current size of Newspace
    there are other memory areas described in the book
    http://www.oracle.com/technology/pub/articles/mensah_dws.html
    http://www.elsevier.com/wps/find/bookdescription.cws_home/706089/description#description
    Sample chapter: http://www.oracle.com/technology/books/pdfs/mensah_ch1.pdf
    Kuassi

  • App Memory Leak When Open iPhoto

    Hi everyone,
    Does anyone have experienced app memory leak when open iPhoto?  My free memory immediate dropped from 5000 mb to 15mb when I open iPhoto and the app never open.  If I force to quit iPhoto, all return to normal and everything work fine.  I only have iPhoto app running, not sure what caused the memory leak??? 
    Looking for help. 
    Thanks
    JHML

    Actually the new library was a test to see if the problem occurred only with your current library or with all libraries.  The fact that switching libraries cleared up the problem is just serendipitous. 

  • Memory Leak when TOMCAT connects to Oracle 10g RAC using JDBC Thin driver.

    We had experienced Memory leak when a Oracle 10g (10.2.0.3) RAC node was evicted. TOMCAT app server is connecting to the Oracle 10g RAC database instances using JDBC 10.2.0.3 thin driver.
    Anyone had similar experience?
    Any ideas? Any bugs reported/fixed?
    Thanks,
    Raj

    If you're doing XA, we absolutely do not support
    driver-level load-balancing OR failover. Use neither.
    For non-XA, you can use driver-level failover. For
    non-XA, you could set load-balancing, but it won't
    help because we get connections from the driver,
    and keep them indefinitely, so the driver never gets
    the chance to affect which connections the pool
    uses after that.

  • Memory leak when using Threads?

    I did an experiment and noticed a memory leak when I was using threads.. Here's what I did.
    ======================================
    while( true )
         Scanner sc = new Scanner(System.in);
         String answer;
         System.out.print("Press Enter to continue...");
         answer = sc.next();
         new TestThread();
    ========================================
    And TestThead is the following
    ========================================
    import java.io.*;
    import java.net.*;
    public class TestThread extends Thread
    public TestThread() { start(); }
    public void run() {  }
    =====================================
    When I open windows Task Manager, every time a new thread starts and stops, the java.exe increases the Mem Usage.. Its a memory leak!? What is going on in this situation.. If I start a thread and the it stops, and then I start a new thread, why does it use more memory?
    -Brian

    MoveScanner sc = new
    Scanner(System.in);out of the
    loop.Scanner sc = new Scanner(System.in);
    while (true) {
    That won't matter in any meaningful way.
    Every loop iteration creates a new Scanner, but it also makes a Scanner eligible for GC, so the net memory requirement of the program is constant.
    Now, of course, it's possible that the VM won't bother GCing until 64 MB worth of Scanners have been created, but we don't care about that. If we're allowing the GC 64 MB, then we don't care how it uses it or when it cleans it up.

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

  • Memory leak when running in database

    I am somewhat new to java and very new to java in the db. I just ran into a problem with what appears to be a memory leak. I have a substantial java program used to parse XML files. I developed this app in jDeveloper and for testing purposes created a method that would connect to the database so that I could run the app from jDeveloper instead of having to deploy it everytime i needed to run it. When deployed the application uses the existing connection to connect to the db.
    I am running Oracle 9i on a windows 2k machine.
    When I run the application through jDeveloper the javaw.exe process takes up roughly 20mb of RAM and doesn't increase. I also watched the oracle.exe process and there was little to no increase in the RAM that it was using.
    When deployed to a db and run through a java stored procedure the RAM used by the oracle.exe process sky rockets, jumping from 70mb to 139mb at about 2mb per second.
    Hopefully this will make some sense to someone as posting code would be somewhat difficult considering the size of the project. Is there something I'm missing? I've tried calling the garbage collector explicity but it has had no effect. I have made sure that all my cursors, statements, resultsets are closing. I have a number of Vecotors which are all being de-allocated(as far as i can tell). Are there any known issues with the garbage collector in a 9i DB?
    Thanks
    Butch Wesley

    The size of oracle.exe is not an indication of how the Java VM GC works; so you are not comparing apples to apples. It'll be too long to explain here but in my upcoming book (see hereafter), I gave a detailled explanation of the various memory areas the Java VM uses and how these are GCed and also how you can meausre their size (not all, though).
    In short you want to use OracleRuntime methods such as
    OracleRuntime.getSessionSize(); --> get he current size of Sessionspace
    OracleRuntime.getNewspaceSize(); --> get he current size of Newspace
    there are other memory areas described in the book
    http://www.oracle.com/technology/pub/articles/mensah_dws.html
    http://www.elsevier.com/wps/find/bookdescription.cws_home/706089/description#description
    Sample chapter: http://www.oracle.com/technology/books/pdfs/mensah_ch1.pdf
    Kuassi

  • Photoshop CS6 memory leak when idle and nothing open

    Photoshop CS6 runs away with memory after being used and then going idle. If I open up PS and leave it, it will be ok but as soon as I open any file it will go up in memory usage (which is normal) but when I close all files and hide PS the memory will stay high never goes back down. When I close PS and re-open (no files open) again it idles at 300Mb memory but when I open a file then close it and then hide/idle PS it raises and stays around 1.25-1.5 GB if not more.
    I have tried to Purge All, and even hide all menus to no avail. I have even tried to close Suitcase (eleminiate any font issues) and still same problem. I am running PS bone stock, no extra plug-ins. 
    Any ideas on why it would be doing this would be greatly appreciated!
    My Computer:
    Photoshop 13.0.1
    MacBookPro
    OS 10.6.8
    CPU: 2.66 GHz Intel Core 2 Duo
    Mem: 4 GB 1067 MHz DDR3
    HD: 300GB (30GB Free)

    Photoshop is not supposed to free memory when you close documents -- that's normal, because the memory gets reused.
    Yes, opening a file makes the memory usage go up - because space is needed for the document and it's window.
    None of what you said describes a leak, and sounds like perfectly normal behavior.

  • Memory leak when "Use JSSE SSL" is enabled

    I'm investigating a memory leak that occurs in WebLogic 11g (10.3.3 and 10.3.5) when "Use JSSE SSL" is checked using the Sun/Oracle JVM and JCE/JSSE providers. The leak is reproducible just by hitting the WebLogic Admin Console login page repeatedly using SSL. Running the app server under JProfiler shows byte arrays (among other objects) leaking from the socket handling code. I thought it might be a general problem with the default JSSE provider, but Tomcat does not exhibit the problem.
    Anyone else seeing this?

    Yes, we are seeing it as well on Oracle 11g while running a GWT 2.1.1 application using GWT RPC. Our current fix is to remove the JSSE SSL configuration check, however this might not be an option if you really need it for your application. Have you found anything else about it?

  • Memory leak when using DB_DBT_MALLOC in CDB.

    Hello!
    Recently when I'm using Berkeley DB CDB and set the value Dbt DB_DBT_MALLOC, I noticed that the app's memory keeps growing during the db.get while;
    I found that many codes on the internet use the syntax free(value.get_data()), but when I tried to free the value.get_data(), I always got an interruption error.
    It's OK when I'm using the DB_DBT_USERMEM flag. So I just get very confused about the DB_DBT_MALLOC and DB_DBT_REALLOC.
    And also, I wonder why there's no memory leak problem when we use the single thread BDB. I think BDB cannot free the value.data pointer too in single thread before the app finish using it, then why our apps don't need to free the data afterwards?
    Thanks a lot in advance!

    You should use free() to free the DBT memory allocated via DB_DBT_MALLOC. You should do that after each Db::get() operation (and of course after finishing processing/using the data), otherwise you will loose the pointer to the memory previously allocated if you happen to reuse the DBT with DB_DBT_MALLOC (the data field will point to a new memory address).
    Alternatively you could use DB_DBT_REALLOC or DB_DBT_USERMEM.
    Note that there are small structures that BDB creates in the environment regions that only get freed/cleaned when the environment is closed.
    If you suspect that there is a memory leak inside the BDB code, make sure you rebuild Berkeley DB using the following configuration options (along with the others you use) when building: enable-debug, enable-umrw. Than, run the program under a memory leak detection utility, like Valgrind (allow the application to open and close the BDB environment) and see if there are any leaks reported.
    If memory leaks are reported, then put together a small stand-alone test case program that demonstrates the leaks, and post it here.
    Regards,
    Andrei

  • Memory leak when LineUnavailableException thrown

    I think I've found a Java bug that I'd like to run past you folks first before submitting it; perhaps you've come across this and can confirm it also?
    I play audio clips (using javax.sound in 1.3.1_02 and 1.4.0-b92) in my app on certain events but if the audio system is unavailable a LineUnavailableException gets thrown when I do clip.open(stream). I retry playing the audio pausing each time, until I reach a timeout and then give up.
    Every time the exception is thrown I can see the JVM swallow more memory (about 500k on WinNT 4.0); which is a major problem if the app ends up retrying lots of audio.
    This is VERY easy to reproduce with the Java Sound Demo! All you need do is keep the audio system busy - play some MP3s/a CD etc then set up some AU/WAVs in the Java Sound Demo on a loop and watch it throw LineUnavailableExceptions in your cmd window! Bring up Task Manager then watch the JVM grow in size as it gobbles up memory and doesn't release it. It'll go from 15Mb to 50Mb in 60 seconds. It also seems to bypass the -Xmx max JVM memory setting also, presumably due to the allocs happening in native code??
    Anyone else seen this or care to reproduce just in case I'm going mad?
    cheers,
    - Justin

    Note that there was a similar bug reported which this seems very related to...
    "Memory leaks on opening and closing source DataLines"
    http://developer.java.sun.com/developer/bugParade/bugs/4319431.html
    - Justin

  • Memory leak when browsing through records

    Hello,
    I have a problem with any page containing the component related to each other on three or more levels. (1st level ADF Table, 2nd level ADF Table and 3rd level ADF Form)
    By navigating through the records of the first level, there is refreshment at other levels (using partial triggers), but suddenly there is loss of memory (memory leak) for components of type Select One Choice.
    Precisely, the problem appears when browsing another Show Detail Item in the same page.
    Screenshot showing the Data Control in my page: [http://www.infotun.net/usersimages/1/adf/structure.jpg]
    Capture screen representing the initial state where all is well: [http://www.infotun.net/usersimages/1/adf/initial.jpg]
    Capture screen representing the final state after memory loss: [http://www.infotun.net/usersimages/1/adf/final.jpg]
    I'm using JDeveloper Studio 11.1.1.2.0
    JDK: 1.6.0_14
    Operating System: Windows 7.
    Any help/advice is highly appreciated !
    Thanks
    Edited by: InfoTun on 10 juin 2012 16:22
    Edited by: InfoTun on 10 juin 2012 16:26

    Hi,
    the screenshot does not indicate a memory leak. Memory leaks show by the server memory consumption that leads to slow performance or stale applications. Your issue seems to be different from that and doesn't really explain in the screen shots. If you have a support contract then customer support is the recommendation I like to give
    Frank

  • Memory leak when creating new thread.

    Hi,
    Each time i create a thread, it causes 8 bytes memory leak. The testing code is as below and you can see mem usage increasing in Windows Task Manager. But if i don't call ::OCIEnvCreate(), no memory leak.
    Memory validator shows the following call stack information:
    ........largest allocation 8 bytes at .......
    =>OraOCIEI10.dll ss_mem_thread_attach
    =>OraOCIEI10.dll sscoresetserverflag
    =>OraOCIEI10.dll slzgetevar
    =>ntdll.dll LdrInitializeThunk
    Anyone knows what is goiing on?
    /Yue
    #include <stdio.h>
    #include <windows.h>
    #include <process.h>
    #include <oci.h>
    static OCIEnv *env;
    static unsigned int counter = 0;
    unsigned __stdcall ThreadFunc(void* pArg)
    counter++;
    printf( "In %uth thread...\n", counter );
    Sleep(100);
    _endthreadex( 0 );
    return 0;
    int main( int argc, const char* argv[] )
         sword rc = ::OCIEnvCreate(&env, OCI_DEFAULT, NULL, NULL, NULL, NULL, 0, NULL );
         for(;;)
              HANDLE hThread;
              unsigned threadID;
              // Create the second thread.
              hThread = (HANDLE)_beginthreadex( NULL, 0, &ThreadFunc, NULL, 0, &threadID );
              WaitForSingleObject( hThread, INFINITE );
              // Destroy the thread object.
              CloseHandle( hThread );
         return 0;
    }

    Hi,
    I'm not suprised.
    OCI offers the feature OCIThreadKey that allow you to store a pointer within a thread context (without using OCIThread, just using natives threads).
    So OCI needs to catch thread creation to be able to register storage for its OCIThread key value and be able, once the thread is finished to call a callback with the pointer value associated with the thread....

Maybe you are looking for

  • Is it possible to have two receive activities in a single bpel process

    Hi, I have a requirement where I will get a input from a service and I have to pass this input dynamically to file adapter which then retrieved the files from a location based on the input provided and passes it to other service. I have used one rece

  • Volume level on Lumia 625 changes by itself

    Hi, On my Lumia 625 I preset the volume to a number (as you do) and after a while it changes to a lower number by itself. Is there any way I can make sure this doesn't happen? Thanks. Solved! Go to Solution.

  • Space really used on TBS

    Hi, executing the following query SELECT b.tablespace_name, a.*, TRUNC (a.segment_size / tbs_size * 100, 2) segment_perc_used, b.tbs_freespace, TRUNC (b.tbs_freespace / c.tbs_size * 100, 2) freespace_perc, c.tbs_size FROM (SELECT SUM (BYTES) / 1024 /

  • How to Identify that which Region is attached to which Jsp page?

    Hi I am working on module Quoting Sales. I have my jsp page qotSCocHeader.jsp . In responsibility AK Developer we have a region QOTSCOCHEADER . As we can see that the jsp page name and the AK region name both are same. Now my doubt here is that : How

  • [COMPLEX DATATYPE] - Cannot create table

    Hello I tried to create a table with a column based on an complex data type from an Xml Schema. 1 -- XML Schema <?xml version="1.0" encoding="UTF-8"?> <!--W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com)--> <xs:schema xmlns:xs="http:/