OutOfMemoryError when compressing with GZipOutputStream

K

Ken DeLong

I'm saving a large amount of data (a video stream: frames of
byte[640*480], 10 fps) to a file. I'm doing it like this:

FileOutputStream fos = new FileOutputStream(fileName);
BufferedOutputStream bos = new BufferedOutputStream(fos);
GZipOutputStream gos = new GZipOutputStream(bos);
ObjectOutputStream oos = new ObjectOutputStream(gos);

.. . .

// on each new frame
oos.writeObject(frame);


This works well with a small number of frames. However, after about
100 frames I get an OutOfMemoryException. I've tried oos.flush()
every 10 frames but it doesn't help.

How can I avoid the memory overflow?
 
B

Boudewijn Dijkstra

Ken DeLong said:
I'm saving a large amount of data (a video stream: frames of
byte[640*480], 10 fps) to a file. I'm doing it like this:

FileOutputStream fos = new FileOutputStream(fileName);
BufferedOutputStream bos = new BufferedOutputStream(fos);
GZipOutputStream gos = new GZipOutputStream(bos);
ObjectOutputStream oos = new ObjectOutputStream(gos);

. . .

// on each new frame
oos.writeObject(frame);


This works well with a small number of frames. However, after about
100 frames I get an OutOfMemoryException. I've tried oos.flush()
every 10 frames but it doesn't help.

How can I avoid the memory overflow?

Where are the frames coming from?
Why do you use an ObjectStream when you can directly write byte arrays?
 
R

Roedy Green

Where are the frames coming from?
Why do you use an ObjectStream when you can directly write byte arrays?

the code is simpler. And the overhead is minimal for a large object
like that. Without it, you need to place your own length field.

For super speed, look into nio.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top