Memory leak via object input stream (yes I'm resetting)

I am seeing that my system is piling up char[] (according to netbeans profiler tool). I am running JDK 1.5 on linux, the client and server code look like this. The strings are piling up on the client side only. the allocation tree looks like this:
char[]
java.lang.String.<init>
java.lang.StringBuffer.toString()
java.io.ObjectInputStream$BlockDataInputStream.readUTFBody(long)
java.io.ObjectInputStream.readString(boolean)
all the way to my client side code for receiving messages.
Does anyone have any suggestions for something I'm missing?
Client side code for receiving messages:
            TaskMessage tm = null;
              try
                   ServerProcessor.debugPrint( "waiting on message from server" );
                   try
                        tm = ( TaskMessage ) fromServer.readObject();
                   catch ( ClassNotFoundException cnfe )
                        System.out.println( "Class not found exception while reading from server" );
              catch ( IOException e )
                   System.out.println( "failed to make connection with server, disconnecting" );
                   m_connector.getProcessor().disconnect();
                   // kill the thread
                   isFinished = true;
              catch ( Exception e )
                   System.err.println( "Caught exception while reading message from server.\nAssuming disconnect, attempting to reconnect" );
                   fromServer = m_connector.reconnect();
                   m_connector.getProcessor().disconnect();
                   isFinished = true;
              // if we have a message then dispatch it
              if ( tm != null )
                   ServerProcessor.debugPrint( "got non-null message from server" );
                   m_connector.serverMessageReceived( tm );
              }Client side code for senting messages:
    public void sendServerMessage( TaskMessage tm )
         try
              ServerProcessor.debugPrint( "Sending message back to server" );
              m_out.writeObject( tm );
              m_out.flush();
              m_out.reset();
              ServerProcessor.debugPrint( "Sent back to server at: " + System.currentTimeMillis() );
         catch ( IOException ioe )
              System.out.println( "Unable to communicate with server." );
              ioe.printStackTrace();
         catch ( Exception e )
              // catch this silently... hopefully to avoid the broken pipe error display ( we handle it... just elsewhere )
         if ( tm.getType() != m_lastMessageType )
              m_lastMessageType = tm.getType();
              Runtime.getRuntime().gc();
              System.out.println( "Remaining memory on client at the start of type " + tm.getType() + ": " + Runtime.getRuntime().freeMemory() );
    }Server Side Code for sending messages:
                             try
                                  out.writeObject( m );
                                  out.flush();
                                  out.reset();
                             catch ( Exception ioe )
                                  droppedClient();
                             }Server side code for receiving messages:
                       // read the message
                        TaskMessage m = null;
                        try
                             // will block here trying to read the clients reply
                             m = ( TaskMessage ) in.readObject();
                             ServerProcessor.debugPrint( "Received message at: " + System.currentTimeMillis() );
                             ServerProcessor.debugPrint( "got client response" );
                        catch ( ClassNotFoundException cnfe )
                             System.out.println( "Unable to locate TaskMessage Class" );
                             cnfe.printStackTrace();
                        }

I do have another memory leak in the system, what I am trying to determine from this post is if the way I am using read and write object may be contributing to that leak. I was hoping someone would be able to look at the communication code and let me know if I'm properly reseting the streams. Then at the very least I can rule this code out as the problem location and continue tracing the use of the read strings throughout the code.

Similar Messages

  • Object Input Stream Memory Allocation / Deallocation

    I�m a developer working on an enterprise application which uses sockets to relay real-time statistics to a distributed client application. The communication between client and sever uses java.net.Socket and java.io.ObjectInputStream.
    The problem that I�ve run into is that the deserialized objects that I get from the OIS.readObject method are still being referenced by the OIS class. The client can not deallocate them after the data is no longer of interest. This causes the client application to eventually run out of memory.
    Is there a way to force the OIS class to release the references so that the memory can be reclaimed by the garbage collector? The only thing I�ve done so far that seems to work is recreating the connection periodically but I would much rather a more elegant solution.
    Thanks
    Trevis.

    Thanks for the replies. I tried resetting the
    connection from the server side but that cause the
    client to reconnect which is something that I wanted
    to avoid. I also tried recreating the
    ObjectOutputStream but that also caused the client to
    need to reconnect. But I do think that I have a
    solution. I switched the
    OutputObjectStream.writeObject() method to
    OOS.writeUnshared() and with this in place it seems
    that the garbage collector is free to reclaim memory
    on my client. I�m getting ready to do more testing
    and I�ll post a follow up if I find a fly in that
    ointment.This is not what writeUnshared() is for. Only the object itself is written unshared, not any objects that it references, so for any but the simplest objects trees, it will not have the desired effect.
    writeUnshared() exists to allow the reader to do a corresponding readUnshared(), and which is in turn provided to close an obscure security hole.
    Sylvia

  • How can I tell if an Object Input Stream has more objects to read?

    I have a utility that I'm working on where objects are sent via the network as a complete file. I read the objects, update some, and send them back. I never know how many objects are in the file. I cache the file locally prior to performing this operation. It runs in a chron job.
    Currently I am reading until I get an EOF exception. Is there a better way? I've tried available() but it is always returning me zero.
    Thanks.
    ST

    The API says:
    Any attempt to read object data which exceeds the
    boundaries of the custom data written by the
    corresponding writeObject method will cause an
    OptionalDataException to be thrown with an eof field
    value of true.
    Hope this helpsThis doesn't help at all. It refers to what happens while you are reading a single object, not to what happens when you try to read a new object. You will not get this exception between objects.
    If as I suspect you are reading from a socket you really have no choice but to try the read, maybe with a timeout. EOF is the only condition that can reliably indicate that there are no more objects in this stream.

  • Object Input Stream Question

    Hello,
    I am writing a client/server model utility that uses object i/o streams connected to sockets in order to transfer objects between the client and the server. The client and server are seperate packages but the object definition code is identical. Whenever I attempt to perform a transfer from the client to the server I get a class not found exception conmplaining about the full class name including the package name of the client. Is there a way other than the one below to case the object so that it uses the local definition of the object instead of the one from the client side?
    SEVERE: Class not part of the package java.lang.ClassNotFoundException: atsoutag
    escanner.MaintenanceTicket
    Client Code:
                    ObjectOutputStream oos = new ObjectOutputStream(securesoc.getOutputStream());
                    for(int i=0;i<ticketArray.length;i++){
                        oos.writeObject(ticketArray);
    Server Code:ObjectInputStream ois = new ObjectInputStream(SecureClient.getInputStream());
    for(int i=0;i<count;i++){
    ticketArray[i] = (netcooloutageserver.MaintenanceTicket) ois.readObject();

    (a) If two classes are in different packages, they are different classes, regardless of their name or content.
    (b) If you are sending an object of class X it is received as an object of class X.
    Why would you want it any other way? and why would you duplicate the same source code in two different places? That's just a recipe for disaster anyway. Consider what will happen over time and maintenance - they will inevitably diverge. Is that what you want?
    Put the shared class(es) into a package that's shared between the sender and the receiver.

  • Sending defaultTableModel via object output stream

    Hello,
    The defaultTableModel is make me crazy!
    The problem is;
    I have one server and x client.
    When new client is connected to the server, server sends the new client list in defaultTableModel.
    But only the last client is receive the new list.
    All other clients defaultTableModel.getrowCount returns 0
    Here are the codes:
    http://www.adatoz.com/files/java/daServer.java
    http://www.adatoz.com/files/java/daClient.java
    http://www.adatoz.com/files/java/aaServerThread.java
    first run server :-)
    then clients..
    first client nick list is okay.
    but when the second client was come, first client list is zero..
    Thank you,

    When you send the DefaultTableModel, you have sent a copy. When you resend it send the refrence again, but not the values. Thus once you send a object in an ObjectStream sending it again will not update it.
    What you need to do is send a new Vector containing the new data.

  • Object input stream variable not recognized

    this is the code:
    try
    ObjectInputStream inp = new ObjectInputStream(new FileInputStream (file1));
    catch(IOException e)
    e.printStackTrace();
    //reading an object into a string.
    while ((contact = (String) inp.readObject()) != null)
    the error is that the symbol inp can not be resolved.
    Also I have another question? what will read object read from a file.
    will one line in the file = 1 object/

    That's because "inp" only has scope within the try-catch block. Use this:
    try
        ObjectInputStream inp = new ObjectInputStream(new FileInputStream(file1));
        //reading an object into a string.
        while ((contact = (String) inp.readObject()) != null)
    catch(IOException e)
        e.printStackTrace();
    }Or you can move the declaration of "inp" before the try-catch block.

  • Object input stream

    how can i know if a objectinputstream is empty or not? hers what im doing but dont seem to work
    ois = new ObjectInputStream(new FileInputStream("interns/*.id"));
    if(ois.equals(null))
    JOptionPane.showMessageDialog(null, "cannot process...", "id rejected! unknown member of the compagny",JOptionPane.ERROR_MESSAGE);
    }

    then how can i check in a directory if theres at least one file called with a extension equals to '.id'?

  • Help with input streams

    hello/
    i need an InputStream for the constructor of my SAXBuilder object below.
    i have this working, however, i would like to read everything from the
    InputStream first and save the value into a String object before I pass the InputStream to the SAXBuilder. how do i go about doing this?
    thx/f
    // Open an input stream to the URL and read it into a byte array.
    BufferedInputStream bufferedInput =
    new BufferedInputStream(connection.getInputStream());
    // Create a new SAX builder.SAXBuilder builder = new SAXBuilder();
    // Read the portal response back and save it as an XML document.
    Document response = builder.build(bufferedInput);

    But you have now read from your input stream and need to reset it so
    InputStream is = urlConn.getInputStream();
    if ( is.markSupported() ) {
       is.reset();
    else {
       is.close();
       is = new ByteArrayInputStream( docStr.toString().getBytes() );
    Now you can pass your InputStream into your SaxBuilder, and have your string of what it contains.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Can't find the memory leak in Managed Object

    Hey guys...I am trying to find the memory leak that Instruments says I have in this section of code setting up a managed object:
    oCurrentSection = (Section*) [NSEntityDescription insertNewObjectForEntityForName:@"Section" inManagedObjectContext:[[CoreDataManager sharedData] oManagedObjectContext]];
    oCurrentSection.nsSectionName = [attributeDict objectForKey:@"name"];
    oCurrentSection.nsImgUrl = [attributeDict objectForKey:@"imgURL"];
    oCurrentSection.nsDesc = [attributeDict objectForKey:@"desc"];
    oCurrentSection.iOrder = [NSNumber numberWithInt: [[attributeDict objectForKey:@"order"] intValue]];
    Can anyone help me out?

    Thanks everyone! That makes a lot more sense. Yes, kjon, I do come from windows. But please don't reference my troubled past. Actually, I typically use "ps aux | sort -n +3 | tail -1" rather than simply "ps aux" - I just wanted to make sure I wasn't missing something by looking at only the top memory-user. Glad to know there's no massive memory leak in my system
    Procyon, what's wrong with a huge swap? Wouldn't you do it too if you were given a system with 200GB hdd more than necessary and told to make a webserver?
    [root@norpass ~]# df -H
    Filesystem Size Used Avail Use% Mounted on
    /dev/sda3 7.9G 1.1G 6.8G 14% /
    none 1.1G 0 1.1G 0% /dev/shm
    /dev/sda1 40M 9.9M 28M 27% /boot
    /dev/sda4 238G 4.5G 234G 2% /home

  • By any chance long living filestream object cause unmanaged memory leak?

    Hi,
    I am running my application where in I have one file stream object which live for long duration, say its life time is equivalent to life time of application. So by any chance this kind of object causes unmanaged memory leak in the application. Because when
    I see private bytes for my application, it is higher than the all bytes in heap counter. That mean there is a unmanaged memory leak. So does such filestream object cause such behaviour?
    Thanks and Regards,
    Lucas

    What makes you think it's the file stream that leaks unmanaged memory? There could be other parts of your applications that do that.
    FileStream doesn't usually allocate unmanaged memory. Its internal buffer is a GC heap allocated byte[] array. The only unmanaged memory allocation that I know of in FileStream is a OVERLAPPED structure used for async I/O. If you use BeginRead/Write make
    sure you call EndRead/Write correctly, otherwise that structure may be leaked.
    @Joel Engineer: "When a stream uses ASCII encoding under certain cases nulls are added to the data for block alignment."
    FileStream doesn't have anything to do with text encoding and I've told you that before. Next time when I run into a post that makes such a claim I'll simply delete it. This display of ignorance has lasted more than enough.

  • Memory Leak in Input Subsystem 10.3.2.798

    See screenshot. After reboot it drops back down to about 50-60MB but after a while it starts climbing again. This is happening on my Classic with 10.3.2.798.
    I have 3 languages enabled on mine, English QWERTY, Chinese Handwriting and Chinese Pinyin and switch between them, mostly in the Browser.
    http://imgur.com/cdYzu5b

    Update: The input peaked at 499.3MB yesterday. The memory leak seems to occur when I use ALT+ENTER to switch input methods. System displays the list of input types, but at the same time sends a "Submit" to the underlying text field and address bar and the search starts with no text, with the input menu still displayed. Then at that point it starts to leak memory. Please look into this. I had my device rebooted countless times within a week and never had this before 10.3.2.

  • Memory leak problem while passing Object to stored procedure from C++ code

    Hi,
    I am facing memory leak problem while passing object to oracle stored procedure from C++ code.Here I am writing brief description of the code :
    1) created objects in oracle with the help of "create or replace type as objects"
    2) generated C++ classes corresponding to oracle objects with the help of OTT utility.
    3) Instantiating classes in C++ code and assigning values.
    4) calling oracle stored procedure and setting object in statement with the help of setObject function.
    5) deleted objects.
    this is all I am doing ,and getting memory leak , if you need the sample code then please write your e-mail id , so that I can attach files in reply.
    TIA
    Jagendra

    just to correct my previous reply , adding delete statement
    Hi,
    I am using oracle 10.2.0.1 and compiling the code with Sun Studio 11, following is the brief dicription of my code :
    1) create oracle object :
    create or replace type TEST_OBJECT as object
    ( field1 number(10),
    field2 number(10),
    field3 number(10) )
    2) create table :
    create table TEST_TABLE (
    f1 number(10),f2 number (10),f3 number (10))
    3) create procedure :
    CREATE OR REPLACE PROCEDURE testProc
    data IN test_object)
    IS
    BEGIN
    insert into TEST_TABLE( f1,f2,f3) values ( data.field1,data.field2,data.field3);
    commit;
    end;
    4) generate C++ classes along with map file for database object TEST_OBJECT by using Oracle OTT Utility
    5) C++ code :
    // include OTT generate files here and other required header files
    int main()
    int x = 0;
    int y = 0;
    int z =0;
    Environment *env = Environment::createEnvironment(Environment::DEFAULT);
    Connection* const pConn =
    env->createConnection"stmprf","stmprf","spwtrgt3nms");
    const string sqlStmt("BEGIN testProc(:1) END;");
    Statement * pStmt = pConn->createStatement(sqlStmt);
    while(1)
    TEST_OBJECT* pObj = new TEST_OBJECT();
    pObj->field1 = x++;
    pObj->field2 = y++;
    pObj->field3 = z++;
    pStmt->setObject(1,pObj);
    pStmt->executeUpdate();
    pConn->commit();
    delete pObj;
    }

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

  • Memory Leak in my DnD Transferable object

    Hi,
    I need to remove obsolete Collection references to prevent a
    memory leak. I can do this simply by calling ArrayList.clear().
    However, I need to know "when" to clear the list.
    I have a java.awt.datatransfer.Transferable which uses an
    Arraylist. However, if I don't clear the array list, then I have
    a loitering reference which cannot be garbage collected until
    it is first removed from the list.
    So when is the Transferable no longer needed? Is it after
    exportDone() is called? What happens to the transferable when
    there is an exception with the data flavors, is exportDone()
    always called in that case?
    Thanks,
    James

    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.

  • I've noticed this especially when I youtube or video stream for a while. Switching between tabs takes 3-4 seconds. Definitely a memory leak! Is it a general problem or addon specific?

    I've noticed this especially when I youtube or video stream for a while. Switching between tabs takes 3-4 seconds.
    Definitely a memory leak! Is it a general problem or addon specific?
    Also, when I try to close firefox and restart it, the process doesn'y get killed with the normal Command + Q in Mac.
    I need to use Force Quit instead.

    Try updating Flash. You appear to be running an older version dating from September 2010 which might be the cause of the problem. Download from http://get.adobe.com/flashplayer/
    If the problem persists after updating, try running Firefox in [[Safe Mode]]. If it functions properly in that configuration, then one of your add-ons is the culprit.

Maybe you are looking for

  • Why does my 3rd generation iPod touch freeze and crash randomly?

    My sister has a used 3rd Gen iPod touch. It looks fine, not much physical damage beyond normal wear. But it will continuly randomly freeze and crash. It will shut off and we have to turn it back on, only to have it crash again. The frequency of this

  • Why is Youtube not recognizing my Adobe Flash Player Add-On?

    I just did the auto update so that Firefox 17.0 was installed. Anyway, for whatever reason, Youtube only seems to notice that my Adobe Flash Player add-on exists when it wants to. At the moment, it's not recognizing it, so I can't play videos. I've h

  • Modifying a pdf page using Javascript

    Hi all, - I am having an html report that consists of many html pages. - Each page of these html pages contains a table or more, in addition to some buttons that hides/display specific rows in these tables. And these buttons are programmed using Java

  • Games for apple tv

    how do i play games on my ipad and tv at the same time?

  • Sap  (ale/idco's)

    hi thsi si viswa i want ale/idoc customising (including application and tables also customising) outbound and inbound process customising segmant and idoc;s