DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005

    OutOfMemory Error

    Hi there,

    I've been working on a project that uses Servlets on the server-side and an Applet on the client-side. The applet contains a JList. When loading, the applet sends a request to a servlet for data from a database. The servlet obtains the necessary records and loads a 2D array. I made a serialized class named TableData which wraps the 2D array. The servlet then sends the TableData object out the wire using the writeObject() method. The applet then receives the TableData object with the readObject() method and extracts the 2D array in order to load the JList.

    I rudely discovered that this approach only works if the data being sent consists of only 15 - 20 records from the database. Otherwise, anything greater than 20 records, I wind up with this OutOfMemory Error message. This is not good! I hate these kind of gotchas!

    I'm sure there must be many out there who have loaded JLists or JTables with data in applets before. Is there a better approach to this problem than the one I just described that avoids this OutOfMemory error?


  2. #2
    Join Date
    Oct 2004
    I had a similar problem when creating a webpage from a servlet. The problem lies in the fact that you are first contructing the entire object in memory on the server before you are writing to the client. What you should do is start writing to the client as soon as possible. So when you read the first record from the recordstore, imidiately write it to the client. This keeps the server memory clear, since there's no longer any need to store the data there. You might need to rethink you communications protocol a bit though.

  3. #3
    Join Date
    Feb 2005
    As it stands now, I'm wrapping the 2D array of data in a class named TableData, and sending the whole data at once to the applet. Are you saying, perhaps, I should send one record at a time to the applet using the same approach? This would mean using a looping structure at each end, I think. Or do you have something else in mind?


  4. #4
    Join Date
    Aug 2004
    Dublin, Ireland
    I think a looping solution is good, because then the client side will never look stalled, lagged or crashed. So as data comes into the client, update the GUI with the new record.
    Think of an extreme case, returning 5000 records (assuming you didn't receive the OutOfMemory Exception) - the client might be waiting a long time for the data to come through.
    VBForums.com & DevX.com Super Moderator
    Microsoft MVP : Visual Developer - Visual Basic
    My Website

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.