Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET An unhandled exception of type ‘System.OutOfMemoryException’ occurred in xceed.compression.dll

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20009 |

    Hi

    I have been using CompressedStream as part of web service with out any problem until it tried to decompress large amount of data (more than 300 MB), The error message is ‘System.OutOfMemoryException’

     Is there any way around it? If I do not use CompressedStream, it runs ok …

    Thanks

     

    Imported from legacy forums. Posted by Garry (had 2396 views)

    User (Old forums)
    Member
    Post count: 23064

    Do you decompress data directly to disk or in a MemoryStream? If you decompress in a MemoryStream, the decompress data will go directly into RAM memory and can cause this exception.

     

    Is this the compressed or decompressed size?  If it is the compressed size, and the compression ratio is high, then the decompression size can be much bigger, exceeding the available memory, explaining the memory exception.

    Imported from legacy forums. Posted by André (had 480 views)

    User (Old forums)
    Member
    Post count: 23064

    The response stream from the http request is passed to CompressedStream (see codes below). Then, the CompressedStream decompresses it to the disk. So, I’m not sure how I can decompress data to disk directly (please advise).

    The size is the decompressd size.

    WebRequest wReq = WebRequest.Create(http://hello.com);
    wReq.Timeout = Timeout.Infinite;
    WebResponse wRes = wReq.GetResponse();

    Stream stream = wRes.GetResponseStream();
    Xceed.Compression.Licenser.LicenseKey = “ZIN10-EBAUD-ZZZZ”;
    CompressedStream compStream =
    new CompressedStream( stream );

     

    FileStream fs;
    fs =

    new FileStream(destination,FileMode.Create);
    byte[] buffer = new byte[32768];
    int bytesRead=0;

    while( ( bytesRead = compStream.Read( buffer, 0, buffer.Length ) ) > 0 ){
    fs.Write (buffer, 0, bytesRead);
    fs.Flush();
    }
    fs.Flush();
    fs.Close();
    compStream.Close();
    //automatically close stream

    Imported from legacy forums. Posted by Garry (had 328 views)

    User (Old forums)
    Member
    Post count: 23064

    Your code seems fine, that’s what we had in mind.  This should work if the system resources are enough.

    You could try to wrap a .NET stream around the response stream, just to see if you get the same exception.  This would indicate the problem is not with CompressedStream.  You can try with BufferedStream or DeflateStream.

     

    Imported from legacy forums. Posted by André (had 1959 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.