I am trying to read serialized objects from mysql database in a loop and perform some operations on it in java. I have written the following function for returning me the object from ResultSet the object.
public static MyObj deSerializeCacheTagInfo(ResultSet res
    ) throws SQLException, IOException, ClassNotFoundException 
{
    byte[] buf = res.getBytes(3);
    ObjectInputStream objectIn = null;
    if (buf != null)
        objectIn = new ObjectInputStream(new ByteArrayInputStream(buf));
    MyObj info = (MyObj)objectIn.readObject();
    return info;
}
When I run this code, it gives me an out of memory exception. I searched around a bit and realized it could be because result set is large and it is kept in memory, so I tried fetching some 50 rows at a time.
But that doesn't seem to help either.
On profiling with visualvm, it reports that all the space is being hogged by byte[] objects.
But I am not entirely sure what's going wrong.
 
     
     
     
    